/* MOCHI GAME BOY · 页面层样式
   屏幕内容不在这里：它在 src/ui/screen-content.js 里用 Canvas2D 绘制，最后贴到 3D LCD 上。
   约定：#chrome / #overlay 整层 pointer-events:none，可交互元素单独恢复 auto。 */

:root {
  --bg-top: #F7F5EE;
  --bg-bottom: #E3E0D6;
  --bg-edge: #DCD8CD;
  --paper: #F6F0E1;
  --ink: #221F29;
  --ink-soft: #6E6A78;
  --gold: #D2AE6B;
  --ink-04: rgba(34, 31, 41, 0.04);
  --ink-08: rgba(34, 31, 41, 0.08);
  --ink-12: rgba(34, 31, 41, 0.12);
  --ink-18: rgba(34, 31, 41, 0.18);
  --font-sans: "Helvetica Neue", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --pad-x: clamp(20px, 3.4vw, 52px);
  --pad-y: clamp(16px, 3vh, 32px);
  --safe-bottom: 130px;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(90% 72% at 50% 22%, var(--bg-top) 0%, rgba(247, 245, 238, 0) 72%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 78%, var(--bg-edge) 100%);
  color: var(--ink);
  overflow: hidden;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- 舞台 ---------- */
#stage { position: fixed; inset: 0; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }
#chrome, #overlay { position: absolute; inset: 0; pointer-events: none; }
#chrome { z-index: 5; }
#overlay { z-index: 10; }

button { font-family: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }

/* ---------- 载入层 ---------- */
#loader {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-content: center; gap: 12px; justify-items: center;
  background: var(--bg-top);
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}
#loader.is-done { opacity: 0; visibility: hidden; }
.loader-mark { font-size: 11px; font-weight: 500; letter-spacing: 0.5em; color: var(--ink-soft); }
.loader-hint { font-size: 11px; letter-spacing: 0.3em; color: var(--ink-soft); opacity: 0.55; }

/* ---------- 顶栏 ---------- */
/* 顶栏：左上 brand，右上分区导航（与 brand 同一水平线，避开下方 3D 卡带） */
.chrome-top {
  position: absolute;
  top: var(--pad-y);
  left: var(--pad-x);
  right: var(--pad-x);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.chrome-brand-block { flex: 0 1 auto; min-width: 0; }
.chrome-brand { display: flex; align-items: center; gap: 12px; }
.chrome-brand__mark {
  font-size: 12px; font-weight: 500; line-height: 1;
  letter-spacing: 0.44em; color: var(--ink);
}
.chrome-brand__rule { width: 26px; height: 1px; background: currentColor; opacity: 0.28; }
.chrome-brand__name {
  font-size: 10px; line-height: 1;
  letter-spacing: 0.36em; color: var(--ink-soft);
}
.chrome-top__sub {
  margin: 12px 0 0;
  font-size: 11px; letter-spacing: 0.16em; color: var(--ink-soft); opacity: 0.9;
}
.chrome-top__right {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-top: -7px;
  pointer-events: none;
}

/* ---------- 底栏 ---------- */
/* 底栏：底部 130px 为安全区（3D 卡带不会下到这里）。
   安全区内导航靠右上、提示靠左下，中间留空，避免压住卡带。 */
.chrome-foot {
  position: absolute;
  left: var(--pad-x);
  right: var(--pad-x);
  bottom: 0;
  height: var(--safe-bottom);
  pointer-events: none;
}
.chrome-hint {
  position: absolute;
  left: 0;
  bottom: 24px;
  margin: 0;
  max-width: min(560px, 46vw);
  font-size: 11px; line-height: 1.6;
  letter-spacing: 0.14em; color: var(--ink-soft);
}

.chrome-nav {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.2vw, 20px);
  pointer-events: auto;
}
.chrome-nav__item {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 9px 2px;
  border: 0;
  background: none;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.25s var(--ease);
}
.chrome-top__right .chrome-nav__item { padding: 8px 2px; }
.chrome-nav__idx {
  font-size: 9px; letter-spacing: 0.1em;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  transition: color 0.25s var(--ease), opacity 0.25s var(--ease);
}
.chrome-nav__item::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 4px;
  height: 1px;
  background: currentColor;
  opacity: 0.45;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.32s var(--ease);
}
.chrome-nav__item:hover,
.chrome-nav__item.is-active { color: var(--ink); }
.chrome-nav__item:hover::after,
.chrome-nav__item.is-active::after { transform: scaleX(1); }
.chrome-nav__item.is-active .chrome-nav__idx { color: var(--gold); opacity: 1; }
.chrome-nav__item:focus-visible { outline-offset: 2px; }

.chrome-help {
  position: absolute;
  right: 0;
  bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 0 8px 10px;
  border: 0;
  background: none;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  cursor: pointer;
  pointer-events: auto;
  transition: color 0.25s var(--ease);
}
.chrome-help__icon {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border: 1px solid currentColor;
  font-size: 11px;
  letter-spacing: 0;
  line-height: 1;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease);
}
.chrome-help:hover { color: var(--ink); }
.chrome-help:hover .chrome-help__icon { background: var(--ink); color: var(--bg-top); }
.chrome-help[aria-expanded="true"] { color: var(--ink); }
.chrome-help[aria-expanded="true"] .chrome-help__icon { background: var(--ink); color: var(--bg-top); }
.chrome-help:focus-visible { outline-offset: 2px; }

/* ---------- 帮助面板 ---------- */
.help-scrim {
  position: absolute;
  inset: 0;
  background: var(--ink-18);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}
#overlay.is-open .help-scrim { opacity: 1; pointer-events: auto; }

.help-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(480px, calc(100vw - 40px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  padding: clamp(26px, 3.4vw, 40px);
  background: var(--bg-top);
  border: 1px solid var(--ink-18);
  box-shadow: 0 40px 80px -48px rgba(34, 31, 41, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -48%);
  pointer-events: none;
  transition: opacity 0.28s var(--ease), transform 0.34s var(--ease), visibility 0.28s;
}
#overlay.is-open .help-panel {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.help-head { position: relative; padding-right: 44px; }
.help-kicker {
  margin: 0 0 10px;
  font-size: 9px; letter-spacing: 0.34em; color: var(--ink-soft);
}
.help-title {
  margin: 0;
  font-size: 24px; font-weight: 300; letter-spacing: 0.14em; color: var(--ink);
}
.help-lead {
  margin: 18px 0 24px;
  font-size: 12px; line-height: 1.9;
  letter-spacing: 0.04em; color: var(--ink-soft);
}
.help-list {
  margin: 0; padding: 0;
  border-top: 1px solid var(--ink-12);
}
.help-list > div {
  display: flex;
  align-items: baseline;
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid var(--ink-08);
}
.help-list dt {
  flex: 0 0 92px;
  margin: 0;
  font-size: 11px; letter-spacing: 0.1em; color: var(--ink);
}
.help-list dd {
  margin: 0;
  font-size: 12px; letter-spacing: 0.06em; line-height: 1.7; color: var(--ink-soft);
}
.help-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  opacity: 0.7;
}
.help-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-18);
  background: none;
  font-size: 15px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  pointer-events: auto;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.help-close:hover { color: var(--ink); border-color: var(--ink); }
.help-close:focus-visible { outline-offset: 2px; }

/* ---------- 窄屏降级（<720px：顶栏只留 brand + 两个功能键，说明键隐藏） ---------- */
@media (max-width: 720px) {
  :root { --safe-bottom: 92px; --pad-x: 18px; --pad-y: calc(env(safe-area-inset-top, 0px) + 14px); }
  .chrome-top { gap: 12px; align-items: center; }
  .chrome-top__sub { display: none; }
  /* 手机端必须保留「卡带盒 / 夜间」两个入口，否则等于没法用 */
  .chrome-top__right { display: flex; flex: 0 0 auto; margin-top: 0; }
  .chrome-nav { gap: 8px; }
  .chrome-tool {
    margin-left: 0;
    padding: 9px 12px;
    min-height: 38px;
    font-size: 10px;
    letter-spacing: 0.08em;
    gap: 6px;
    background: rgba(255, 255, 255, 0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  .chrome-tool__icon { font-size: 12px; }
  .chrome-help { display: none; }
  .chrome-foot { height: var(--safe-bottom); }
  .chrome-hint {
    max-width: 100%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    padding-right: 8px;
    font-size: 10px;
    line-height: 1.75;
    letter-spacing: 0.06em;
    opacity: 0.92;
  }
  .help-list dt { flex-basis: 76px; }
  .help-panel { width: calc(100vw - 32px); padding: 22px; }

  /* 放大后的像素屏：手机上占满宽度 */
  #zoom-ui .zoom-ui__frame { width: min(90vw, 520px); padding: 14px 18px; border-width: 2px; }
  .zoom-ui__title { font-size: clamp(24px, 7.4vw, 34px); }
  .zoom-ui__art { width: 74px; height: 74px; }
  .zoom-ui__start { font-size: 13px; letter-spacing: 0.22em; padding: 12px 26px 12px 30px; }
}
@media (max-width: 430px) {
  .chrome-brand { gap: 8px; }
  .chrome-brand__mark { font-size: 11px; letter-spacing: 0.32em; }
  .chrome-brand__rule { width: 16px; }
  .chrome-brand__name { font-size: 9px; letter-spacing: 0.28em; }
  .chrome-tool { padding: 8px 10px; font-size: 9.5px; }
  .chrome-tool[data-id="theme"] .chrome-tool__label { display: none; }
  .chrome-hint { font-size: 9px; letter-spacing: 0.04em; }
}

/* ---------- 减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  /* 帮助面板只做瞬时显隐，不做位移动画 */
  .help-panel { transform: translate(-50%, -50%); }
  .help-scrim { transition: none; }
}

/* ---------- 加载 ---------- */
.loader-sub { font-size: 10px; letter-spacing: 0.42em; color: rgba(110,106,120,0.55); margin-top: -6px; }
.loader-track { width: 180px; height: 1px; margin-top: 14px; background: rgba(110,106,120,0.18); overflow: hidden; }
.loader-track i { display: block; height: 100%; width: 0%; background: #6E6A78; }
.loader-pct { font-size: 10px; letter-spacing: 0.22em; color: rgba(110,106,120,0.55); font-variant-numeric: tabular-nums; }


/* ---------- 放大后的像素屏（DOM 覆盖层） ---------- */
#zoom-ui {
  position: fixed; inset: 0; display: grid; place-items: center;
  pointer-events: none; opacity: 0; z-index: 30;
  transition: opacity .45s ease;
  background: radial-gradient(60% 50% at 50% 45%, rgba(247,245,238,.55), rgba(227,224,214,.82));
}
#zoom-ui.is-on { opacity: 1; pointer-events: auto; }
.zoom-ui__frame {
  width: min(74vw, 620px); aspect-ratio: 4 / 3;
  background: #f6f1e3; border: 3px solid #2b2732; border-radius: 6px;
  box-shadow: 0 30px 80px rgba(58,50,70,.26);
  padding: 16px 22px; display: flex; flex-direction: column; align-items: center;
  justify-content: space-between; transform: scale(.93);
  transition: transform .5s cubic-bezier(.2,.8,.2,1);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color: #221f29; image-rendering: pixelated; user-select: none;
}
#zoom-ui.is-on .zoom-ui__frame { transform: scale(1); }
.zoom-ui__bar {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  font-size: 10px; letter-spacing: .18em; color: #6e6a78; text-transform: uppercase;
}
.zoom-ui__art {
  width: 92px; height: 92px; image-rendering: pixelated;
  filter: drop-shadow(0 2px 0 rgba(43,39,50,.16));
}
.zoom-ui__title {
  font-size: clamp(24px, 3.4vw, 40px); font-weight: 700; letter-spacing: .1em;
  text-align: center; line-height: 1.1;
}
.zoom-ui__sub { font-size: 11px; letter-spacing: .06em; color: #6e6a78; text-align: center; }
.zoom-ui__start {
  font-family: inherit; font-size: 14px; font-weight: 700; letter-spacing: .28em;
  padding: 12px 34px 12px 38px; border: 2px solid #2b2732; border-radius: 3px;
  background: #221f29; color: #f6f1e3; cursor: pointer;
  box-shadow: 0 4px 0 rgba(43,39,50,.35); transition: transform .12s ease, box-shadow .12s ease;
}
.zoom-ui__start:hover { transform: translateY(-1px); box-shadow: 0 6px 0 rgba(43,39,50,.3); }
.zoom-ui__start:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43,39,50,.35); }

/* ---------- 顶栏功能按钮 ---------- */
.chrome-tool {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; margin-left: 8px;
  border: 1px solid var(--ink-18); border-radius: 999px;
  background: rgba(255,255,255,0.35); color: var(--ink);
  font-family: inherit; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  cursor: pointer; transition: background .2s ease, transform .2s ease, border-color .2s ease;
}
.chrome-tool:hover { background: rgba(255,255,255,0.7); transform: translateY(-1px); }
.chrome-tool--primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chrome-tool--primary:hover { background: var(--ink); opacity: .88; }
.chrome-tool__icon { font-size: 13px; line-height: 1; }

/* ---------- 夜间主题 ---------- */
html.is-dark {
  --bg-top: #1B1922;
  --bg-bottom: #0E0D12;
  --bg-edge: #0A090E;
  --paper: #262330;
  --ink: #EDE8F4;
  --ink-soft: #9A93AA;
  --ink-04: rgba(237,232,244,0.05);
  --ink-08: rgba(237,232,244,0.09);
  --ink-12: rgba(237,232,244,0.14);
  --ink-18: rgba(237,232,244,0.2);
}
html.is-dark body { color: var(--ink); }
html.is-dark .chrome-tool { background: rgba(255,255,255,0.06); }
html.is-dark .chrome-tool--primary { background: var(--paper); color: var(--ink); border-color: rgba(255,255,255,0.25); }

/* ---------- 3D 卡带盒导航浮层 ---------- */
#lib-hud {
  position: fixed; inset: 0; z-index: 6;
  pointer-events: none; opacity: 0;
  transition: opacity .35s var(--ease);
}
#lib-hud.is-on { opacity: 1; }
.lib-hud__top {
  position: absolute; top: var(--pad-y); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center;
  max-width: calc(100vw - 24px);
}
.lib-hud__nav {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px;
  border-radius: 999px; border: 1px solid var(--ink-12);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 28px rgba(34,31,41,.08);
}
.lib-hud__tabs { display: inline-flex; align-items: center; gap: 4px; }
.lib-hud__tab, .lib-hud__btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid transparent;
  background: transparent; color: var(--ink); font-size: 11px; letter-spacing: .06em;
  cursor: pointer; white-space: nowrap; transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.lib-hud__tab:hover, .lib-hud__btn:hover { background: var(--ink-08); }
.lib-hud__tab.is-active {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.lib-hud__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cat-accent, #888); flex: 0 0 auto;
}
.lib-hud__vol {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px; opacity: .55;
}
.lib-hud__cnt {
  font-style: normal; font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px; opacity: .6; padding-left: 2px;
}
.lib-hud__btn { color: var(--ink-soft); font-size: 10.5px; border-color: var(--ink-12); }
.lib-hud__btn[hidden] { display: none !important; }

.lib-hud__bottom {
  position: absolute; left: 50%; bottom: calc(var(--pad-y) + 34px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(640px, calc(100vw - 28px));
}
.lib-hud__shelf-tip {
  padding: 6px 14px; border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  border: 1px solid var(--ink-12);
  font-size: 11px; letter-spacing: .08em; color: var(--ink-soft);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
#lib-hud[data-mode="category"] .lib-hud__shelf-tip { display: none; }

.lib-card {
  pointer-events: none; opacity: 0; transform: translateY(10px);
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--paper) 92%, white);
  border: 1.5px solid var(--ink-18);
  box-shadow: 0 18px 42px rgba(34,31,41,.14);
  transition: opacity .25s ease, transform .25s var(--ease);
}
#lib-hud[data-mode="category"] .lib-card.is-on {
  pointer-events: auto; opacity: 1; transform: translateY(0);
}
.lib-card__badge {
  width: 48px; height: 48px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid var(--ink-12);
}
.lib-card__badge canvas { width: 30px; height: 30px; image-rendering: pixelated; }
.lib-card__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-card__top {
  display: flex; align-items: center; gap: 8px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px; letter-spacing: .12em; color: var(--ink-soft);
}
.lib-card__slot {
  padding: 1px 6px; border-radius: 4px;
  background: var(--site-accent, var(--ink)); color: #fff; font-weight: 700;
}
.lib-card__url { margin-left: auto; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-card__zh { font-size: 16px; font-weight: 700; letter-spacing: .04em; color: var(--ink); }
.lib-card__sub { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card__actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.lib-card__insert, .lib-card__go {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 14px; border-radius: 8px; font-size: 11.5px; font-weight: 600;
  letter-spacing: .06em; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform .15s ease, opacity .15s ease;
}
.lib-card__insert {
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
}
.lib-card__go {
  background: transparent; color: var(--ink); border: 1px solid var(--ink-18);
}
.lib-card__insert:hover, .lib-card__go:hover { transform: translateY(-1px); opacity: .92; }

@media (max-width: 720px) {
  .lib-hud__top { top: 56px; width: calc(100vw - 20px); }
  .lib-hud__nav { width: 100%; justify-content: center; overflow-x: auto; }
  .lib-hud__vol, .lib-hud__exit, .lib-hud__shelf-tip { display: none; }
  .lib-hud__tab, .lib-hud__btn { padding: 6px 10px; font-size: 10.5px; }
  .lib-hud__bottom { bottom: 38px; width: calc(100vw - 20px); }
  .lib-card { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .lib-card__badge { width: 40px; height: 40px; }
  .lib-card__url { display: none; }
  .lib-card__actions { width: 100%; }
  .lib-card__insert, .lib-card__go { flex: 1; padding: 8px 10px; }
}

/* 放大层：背后压暗一点，避免和 3D 屏叠在一起 */
#zoom-ui { background: color-mix(in srgb, var(--bg-top) 88%, transparent); backdrop-filter: blur(6px) saturate(1.05); -webkit-backdrop-filter: blur(6px); }
#zoom-ui.is-on { background: color-mix(in srgb, var(--bg-top) 90%, transparent); }
