/* 后室 · 主页（js/ui/home.js）。只写 home- 前缀的选择器；z-index 见 ARCHITECTURE.md 第 11 节：主页 50，皮肤色板 70 */

.home-root {
  position: fixed; left: 0; top: 0; width: 100%; height: 100%;
  z-index: 50;
  /* 根节点不吃事件：点空白处要穿到画布上去点人物 */
  pointer-events: none;
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: #f4ecd0;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.home-root[hidden], .home-skin[hidden], .home-modal[hidden], .home-hint[hidden] { display: none !important; }
.home-root button, .home-skin button { font-family: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ---------- 标题 ---------- */
.home-title {
  position: absolute;
  left: calc(20px + env(safe-area-inset-left));
  top: calc(14px + env(safe-area-inset-top));
  pointer-events: none;
  /* 背后是浅黄墙纸和天花板：深棕字 + 浅色描边比白字清楚 */
  color: #2a2006;
  text-shadow: 0 1px 0 rgba(255, 248, 215, .6), 0 0 20px rgba(255, 242, 196, .55);
  transition: opacity .25s ease;
}
.home-title-zh { font-size: clamp(34px, 8vmin, 76px); font-weight: 800; letter-spacing: .14em; line-height: 1.05; }
.home-title-en { margin-top: 4px; font-size: clamp(11px, 2vmin, 18px); font-weight: 700; letter-spacing: .42em; opacity: .9; }

/* ---------- 人物下方提示 ---------- */
.home-hint {
  position: absolute; left: 0; top: 0;
  pointer-events: none;
  white-space: nowrap;
  font-size: 13px; line-height: 1;
  padding: 7px 12px;
  border-radius: 999px;
  color: #2a2006;
  background: rgba(255, 244, 205, .78);
  box-shadow: 0 2px 10px rgba(40, 30, 5, .18);
  transition: opacity .3s ease, background-color .2s ease;
  will-change: transform;
}
.home-hint.is-hover { background: rgba(255, 236, 150, .95); }

/* ---------- 右下角「游玩」 ---------- */
.home-play {
  position: absolute;
  right: calc(24px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  pointer-events: auto;
  min-width: 156px; min-height: 62px;
  padding: 0 46px;
  font-size: clamp(22px, 3.6vmin, 32px); font-weight: 800;
  letter-spacing: .24em; text-indent: .24em;
  color: #1d1705;
  background: linear-gradient(#f5d964, #dcb434);
  border: 2px solid #2c2208;
  border-radius: 12px;
  box-shadow: 0 6px 0 #6b5816, 0 12px 26px rgba(20, 14, 0, .35);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
.home-play:hover { filter: brightness(1.06); }
.home-play:active { transform: translateY(4px); box-shadow: 0 2px 0 #6b5816, 0 6px 14px rgba(20, 14, 0, .3); }
.home-play:focus-visible { outline: 3px solid #fff4c4; outline-offset: 3px; }

/* ---------- 「游玩」正上方：创意工坊 / 设置（次要按钮，WORKSHOP.md 第 9 节） ---------- */
.home-secondary-actions {
  position: absolute;
  right: calc(24px + env(safe-area-inset-right));
  /* 24 + 62（.home-play 默认高）+ 10 间距，随下面几个断点里 .home-play 的高度一起变 */
  bottom: calc(96px + env(safe-area-inset-bottom));
  pointer-events: auto;
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
}
.home-secondary-btn {
  min-width: 130px; min-height: 44px;
  padding: 0 20px;
  font-size: 14px; font-weight: 700;
  letter-spacing: .12em;
  color: #f4ecd0;
  background: rgba(255, 240, 190, .08);
  border: 1px solid rgba(232, 197, 71, .45);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.home-secondary-btn:hover { background: rgba(232, 197, 71, .16); border-color: #e8c547; }
.home-secondary-btn:active { background: rgba(232, 197, 71, .26); }
.home-secondary-btn:focus-visible { outline: 2px solid #e8c547; outline-offset: 2px; }
/* 和 .home-play / .home-credit 一样：主页自己的弹层开着时收起，别跟弹窗叠在一起 */
.home-root.is-open .home-secondary-actions { opacity: 0; visibility: hidden; }

/* ---------- 左下署名 ---------- */
.home-credit {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(10px + env(safe-area-inset-bottom));
  pointer-events: auto;
  min-height: 44px;
  max-width: calc(100% - 230px - env(safe-area-inset-left) - env(safe-area-inset-right));
  padding: 4px 8px;
  border: 0; background: none;
  color: rgba(46, 36, 8, .88);
  font-size: 12px; line-height: 1.35; text-align: left;
  text-decoration: underline; text-underline-offset: 3px;
  text-shadow: 0 1px 0 rgba(255, 246, 210, .45);
  cursor: pointer;
}

/* 有弹层时把主页上的常驻元素收起，免得和弹窗叠在一起 */
.home-root.is-open .home-play,
.home-root.is-open .home-credit,
.home-root.is-open .home-hint { opacity: 0; visibility: hidden; }

/* ---------- 弹窗 ---------- */
.home-modal {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  pointer-events: auto;
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: flex-end;
  padding: calc(12px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right))
           calc(12px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  /* 背景只压暗一点：弹窗在右侧，左边的人物还要看得见 */
  background: linear-gradient(90deg, rgba(14, 11, 3, 0) 30%, rgba(14, 11, 3, .38) 100%);
}
.home-dialog {
  box-sizing: border-box;
  width: min(430px, 50vw);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 18px 18px;
  border-radius: 14px;
  background: rgba(24, 20, 9, .93);
  border: 1px solid rgba(232, 197, 71, .3);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  animation: home-in .18s ease-out;
  -webkit-user-select: text; user-select: text;
}
@keyframes home-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.home-dialog-head { display: flex; align-items: center; gap: 6px; margin: -4px -8px 10px; }
.home-dialog-title { flex: 1; font-size: 19px; font-weight: 800; letter-spacing: .06em; padding: 0 4px; }
.home-back, .home-close {
  min-width: 44px; min-height: 44px;
  border: 0; border-radius: 10px;
  background: transparent; color: #f4ecd0;
  font-size: 15px; cursor: pointer;
}
.home-back { padding: 0 10px; }
.home-close { font-size: 26px; line-height: 1; }
.home-back:hover, .home-close:hover { background: rgba(255, 240, 190, .08); }
.home-back[hidden] { display: none; }

.home-note { margin: 4px 0 12px; font-size: 13px; line-height: 1.55; color: rgba(244, 236, 208, .78); }
.home-note-warn { color: #ffb4a0; }

/* 模式选择：三个大按钮自上而下 */
.home-menu { display: flex; flex-direction: column; gap: 10px; }
.home-menu-btn {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px;
  min-height: 70px; padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(232, 197, 71, .35);
  background: rgba(255, 240, 190, .06);
  color: #f4ecd0; text-align: left; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.home-menu-btn:hover, .home-menu-btn:focus-visible { background: rgba(232, 197, 71, .16); border-color: #e8c547; outline: none; }
.home-menu-name { font-size: 21px; font-weight: 800; letter-spacing: .08em; }
.home-menu-sub { font-size: 12px; line-height: 1.4; color: rgba(244, 236, 208, .7); }
.home-menu-btn.is-nightmare .home-menu-name { color: #ff9c86; }

/* 参数 */
.home-field { margin: 0 0 12px; }
.home-field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 15px; }
.home-field-label { font-weight: 700; }
.home-field-value { font-size: 13px; color: #f1d467; font-variant-numeric: tabular-nums; text-align: right; }
.home-range { display: block; width: 100%; height: 44px; margin: 0; accent-color: #e8c547; background: transparent; cursor: pointer; }
.home-select {
  display: block; width: 100%; min-height: 44px; margin-top: 6px;
  padding: 0 10px;
  font-size: 16px;   /* 小于 16px 时 iOS 聚焦会自动放大页面 */
  color: #f4ecd0; background: #231e0e;
  border: 1px solid rgba(232, 197, 71, .35); border-radius: 8px;
}
.home-select option:disabled { color: #8a826a; }
/* 键盘焦点用主题黄色描边，别用浏览器默认的蓝框 */
.home-dialog :focus-visible, .home-skin :focus-visible, .home-credit:focus-visible { outline: 2px solid #e8c547; outline-offset: 2px; }
.home-dialog :focus:not(:focus-visible), .home-skin :focus:not(:focus-visible) { outline: none; }

.home-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.home-btn {
  flex: 1 1 auto;
  min-height: 48px; padding: 0 18px;
  border-radius: 10px;
  border: 1px solid rgba(232, 197, 71, .4);
  background: rgba(255, 240, 190, .06);
  color: #f4ecd0;
  font-size: 16px; font-weight: 700; letter-spacing: .06em;
  cursor: pointer;
}
.home-btn:hover { background: rgba(232, 197, 71, .14); }
.home-btn:disabled { opacity: .4; cursor: not-allowed; background: rgba(255, 255, 255, .03); }
.home-btn-primary { flex-grow: 2; color: #1d1705; background: linear-gradient(#f3d65e, #dcb434); border-color: #e8c547; }
.home-btn-primary:hover { background: linear-gradient(#f7de74, #e2bc40); }
.home-coop-status { width: 100%; font-size: 12px; color: #9fe3a6; }
.home-coop-status:empty { display: none; }

/* 噩梦难度卡片 */
.home-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.home-card {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 6px;
  min-height: 88px; padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(232, 197, 71, .35);
  background: rgba(255, 240, 190, .05);
  color: #f4ecd0; text-align: left; cursor: pointer;
}
.home-card:hover, .home-card:focus-visible { background: rgba(232, 197, 71, .15); border-color: #e8c547; outline: none; }
.home-card-name { font-size: 20px; font-weight: 800; letter-spacing: .1em; }
.home-card-desc { font-size: 12px; line-height: 1.4; color: rgba(244, 236, 208, .75); }
.home-card-hard .home-card-name { color: #ffb070; }
.home-card-hell { border-color: rgba(230, 80, 60, .55); }
.home-card-hell .home-card-name { color: #ff6f5a; }

/* 署名 */
.home-credits-list { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.5; }
.home-credits-list li { padding: 8px 0; border-top: 1px solid rgba(232, 197, 71, .15); word-break: break-word; }
.home-credits-list a { color: #f1d467; }
.home-credits-key { color: rgba(244, 236, 208, .6); }

/* ---------- 皮肤色板（z-index 70，挂在 #ui 下与主页根节点并列） ---------- */
.home-skin {
  position: fixed; left: 0; top: 0; width: 100%; height: 100%;
  z-index: 70;
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: #f4ecd0;
  -webkit-user-select: none; user-select: none;
}
.home-skin-backdrop { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: rgba(14, 11, 3, .12); }
.home-skin-panel {
  position: absolute;
  right: calc(22px + env(safe-area-inset-right));
  top: 50%; transform: translateY(-50%);
  box-sizing: border-box;
  width: min(360px, 46vw);
  max-height: calc(100% - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 16px 16px;
  border-radius: 14px;
  background: rgba(24, 20, 9, .93);
  border: 1px solid rgba(232, 197, 71, .3);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}
.home-skin-head { display: flex; align-items: center; margin: -2px -6px 8px 0; }
.home-skin-title { flex: 1; font-size: 18px; font-weight: 800; letter-spacing: .06em; }
.home-skin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.home-swatch {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  min-height: 82px; padding: 8px 4px;
  border-radius: 12px;
  border: 2px solid rgba(232, 197, 71, .18);
  background: rgba(255, 240, 190, .05);
  color: #f4ecd0; font-size: 14px; font-weight: 700;
  cursor: pointer;
}
.home-swatch:hover { background: rgba(255, 240, 190, .12); }
.home-swatch-dot {
  width: 36px; height: 36px; border-radius: 50%;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .22), 0 0 0 2px rgba(0, 0, 0, .35);
}
.home-swatch.is-active { border-color: #e8c547; background: rgba(232, 197, 71, .18); }
.home-swatch.is-active .home-swatch-dot { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .22), 0 0 0 3px #fff6d4, 0 0 0 5px #e8c547; }
.home-skin-note { margin: 10px 0 0; font-size: 12px; color: rgba(244, 236, 208, .65); }

/* 悬停在人物上：手型光标（#ui 可能盖在画布上，两处都设） */
.home-cursor-fig, .home-cursor-fig body, .home-cursor-fig #gl, .home-cursor-fig #ui { cursor: pointer; }

/* ---------- 竖屏：弹窗和色板改成底部抽屉，人物由 home.js 重新取景到上半屏 ---------- */
@media (max-aspect-ratio: 17/20) {
  .home-title { top: calc(12px + env(safe-area-inset-top)); }
  .home-root.is-open .home-title { opacity: 0; }
  .home-modal {
    align-items: flex-end; justify-content: center;
    padding: 0;
    background: linear-gradient(180deg, rgba(14, 11, 3, 0) 35%, rgba(14, 11, 3, .38) 100%);
  }
  .home-dialog {
    width: 100%;
    max-height: 56vh; max-height: 56dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    padding: 12px calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  }
  .home-play { min-width: 140px; min-height: 58px; padding: 0 36px; }
  .home-credit { max-width: calc(100% - 200px - env(safe-area-inset-left) - env(safe-area-inset-right)); }
  .home-skin-panel {
    left: 0; right: 0; bottom: 0; top: auto;
    transform: none;
    width: 100%;
    max-height: 50vh; max-height: 50dvh;
    border-radius: 16px 16px 0 0; border-bottom: 0;
    padding: 12px calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  }
  /* .home-play 这个断点里矮到 58px，次要按钮组跟着往下挪，别悬空留大缝 */
  .home-secondary-actions { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* 矮横屏手机：卡片挤一点，标题缩小 */
@media (max-height: 460px) and (min-aspect-ratio: 17/20) {
  .home-title-zh { font-size: 32px; }
  .home-menu-btn { min-height: 58px; }
  .home-card { min-height: 70px; }
  .home-play { min-height: 54px; }
  .home-secondary-actions { bottom: calc(88px + env(safe-area-inset-bottom)); gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .home-dialog { animation: none; }
  .home-title, .home-hint, .home-play { transition: none; }
}
