:root {
  --color-void: #1b1712;
  --color-frame-bg: #f6ede1;
  --color-text: #3a2a1c;
  --color-text-soft: #7a6a58;
  --color-accent: #a9713f;
  --color-accent-soft: rgba(169, 113, 63, 0.18);
  --color-chip-border: #e2d5c0;
  /* 线条一律用融合进背景的浅棕，不勾黑边 */
  --line-soft: #cbb499;
  --line-bold: 2px;
  --color-panel-bg: #fffaf3;
  --color-card-bg: #ffffff;
  --color-card-slot: #f3e8d8;
  --radius-panel: 20px;
  --radius-chip: 18px;
  --radius-button: 999px;
  --space-1: 6px;
  --space-2: 12px;
  --space-3: 20px;
  --space-4: 32px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-touch-callout: none;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--color-void);
  color: var(--color-text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
  /* 禁用 iOS 选中、缩放及橡皮筋下拉效果 */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* 舞台容器：
   自动撑满全屏幕。
   PC端：中心部分有内容，左右空（居中，高撑满屏幕）。
   移动端：以竖屏为基准，必定撑满全屏幕。
*/
#stage {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-frame-bg);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 移动端竖屏：不加宽度限制，全宽全高撑满全屏幕 */
@media (max-width: 640px) {
  #stage {
    max-width: none;
  }
}

/* 移动端横屏锁定：不随屏幕转换改变视图，锁在竖屏中，通过旋转撑满全屏幕 */
body.mobile-landscape {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

body.mobile-landscape #stage {
  position: fixed;
  top: 50%;
  left: 50%;
  /* 宽高互换，保持竖屏比例 */
  width: 100dvh;
  height: 100dvw;
  max-width: none;
  margin: 0;
  transform: translate(-50%, -50%) rotate(var(--landscape-rot, 90deg));
  transform-origin: center center;
}

/* 摇手机时整个画面震一下 */
@keyframes stage-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-7px, 3px);
  }
  40% {
    transform: translate(6px, -4px);
  }
  60% {
    transform: translate(-4px, -4px);
  }
  80% {
    transform: translate(4px, 3px);
  }
}

.stage-shaking {
  animation: stage-shake 0.45s ease-out;
}

#cup-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 主屏幕只有这一个悬浮元素：杯内靠下的一条提示，不是按钮，不接收点击。
   压在杯底上方一点，不挡住上面倒东西的地方，也不压到杯底那条边。 */
.long-press-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 13%);
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-button);
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-soft);
  letter-spacing: 0.05em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.long-press-hint.hint-visible {
  opacity: 1;
}

/* ---- 加料面板：整页的图鉴 ---- */
/* 遮罩：点它就关掉面板 */
.codex-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + var(--space-3)) var(--space-3)
    calc(var(--safe-bottom) + var(--space-3));
  background: rgba(59, 42, 30, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.codex-overlay.codex-open {
  opacity: 1;
  pointer-events: auto;
}

/* 弹窗：居中，高度跟着内容走，内容多了才自己滚 */
.codex {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  padding: var(--space-2) var(--space-2) var(--space-3);
  border-radius: var(--radius-panel);
  background: var(--color-panel-bg);
  box-shadow: 0 10px 30px rgba(59, 42, 30, 0.18);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}

.codex-overlay.codex-open .codex {
  transform: translateY(0) scale(1);
}

.codex-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-bottom: var(--space-2);
}

/* 分类多了以后一行放不下：允许横着滑，右边给关闭按钮留出地方 */
.codex-tabs {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding-right: 44px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: none;
}

.codex-tabs::-webkit-scrollbar {
  display: none;
}

.codex-tab {
  position: relative;
  flex: 0 0 auto;
  padding: var(--space-1) 0;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0.08em;
  color: var(--color-text-soft);
}

.codex-tab::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: var(--line-bold);
  border-radius: var(--radius-button);
  background: var(--color-accent);
  transform: translateX(-50%);
  transition: width 0.18s ease;
}

.codex-tab-active {
  color: var(--color-accent);
  font-weight: 600;
}

.codex-tab-active::after {
  width: 100%;
}

.codex-close {
  position: absolute;
  right: 0;
  top: 50%;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.codex-close-glyph {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--color-text-soft);
  stroke-width: 2.6;
  stroke-linecap: round;
}

.codex-close:active .codex-close-glyph {
  stroke: var(--color-accent);
}

.codex-pages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.codex-pages::-webkit-scrollbar {
  width: 6px;
}

.codex-pages::-webkit-scrollbar-track {
  background: transparent;
}

.codex-pages::-webkit-scrollbar-thumb {
  background: var(--color-chip-border);
  border-radius: var(--radius-button);
}

/* 分类名：居中，两侧各一条细线 */
.codex-group-title {
  margin: var(--space-2) 0 var(--space-1);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  text-align: center;
  color: var(--color-text-soft);
}



.codex-page > .codex-group-title:first-child {
  margin-top: var(--space-1);
}

/* 一行四个，项目不足四个时整排居中 */
.codex-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1);
}

.codex-grid > .codex-card {
  flex: 0 0 calc((100% - var(--space-1) * 4) / 5);
}

/* 卡片没有自己的外框：一个图标加一行名字，挨着排 */
.codex-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-1) 2px;
  border-radius: var(--radius-chip);
  background: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.codex-card-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
}

.codex-card-name {
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  color: var(--color-text);
}

/* 选中：图标后面垫一块圆的底色，名字跟着变色 */
.codex-card:active .codex-card-frame,
.codex-card.codex-card-active .codex-card-frame {
  background: var(--color-accent-soft);
}

.codex-card.codex-card-active .codex-card-name {
  color: var(--color-accent);
  font-weight: 600;
}

/* 清空：工具页最下面的一个文本按钮 */
.codex-clear {
  display: block;
  margin: var(--space-4) auto 0;
  padding: var(--space-1) var(--space-4);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-button);
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0.08em;
  color: var(--color-text-soft);
  text-align: center;
}

.codex-clear:active {
  background: var(--color-accent-soft);
}

/* ---- 图标：描了粗边的图形，和画布上同一套勾线 ---- */
.glyph-svg {
  width: 30px;
  height: 30px;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.glyph-svg-tube {
  fill: var(--color-card-slot);
  stroke: var(--line-soft);
}

.glyph-svg-slot {
  fill: var(--color-text-soft);
}

.glyph-svg-wave {
  fill: none;
  stroke: var(--color-text-soft);
  stroke-linecap: round;
}
