: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;
  --codex-height: 540px;
  /* 弹窗上面一排：左右各留这么宽（右边放关闭按钮），标签在中间那一段里，怎么也压不到关闭按钮 */
  --codex-side: 44px;
  /* 电脑（横着的屏幕）上中间那块画面的宽高比：宽 / 高 */
  --stage-desktop-ratio: 0.68;
  --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;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

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;
}

/* 舞台容器：这套界面就是"一部竖着的手机"。
   竖着的屏幕（手机、平板，包括窗口被拉成竖的电脑）：按屏幕本身的大小铺满，
   不封一个固定宽度——iPad 竖屏铺不满就成了中间一条窄条。
   横着的屏幕：电脑上是一块比手机宽一些的竖屏画面居中，两侧留空；手机上锁死在机身上，
   由下面的 `.stage-rotated` 反着转回去。 */
#stage {
  position: relative;
  width: min(100vw, calc(100dvh * var(--stage-desktop-ratio)));
  aspect-ratio: var(--stage-desktop-ratio);
  max-height: 100dvh;
  background: var(--color-frame-bg);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

@media (orientation: portrait) {
  #stage {
    /* 封顶 3:4 只为挡住"窗口被拉成正方形"这种形状，手机和平板都够不到它 */
    width: min(100vw, calc(100dvh * 3 / 4));
    width: min(100dvw, calc(100dvh * 3 / 4));
    height: 100vh;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
  }
}

/* 锁死竖屏：系统把页面转过去了，就在这里反向转回来，画面固定在机身上 */
body.stage-rotated #stage {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(var(--stage-rot, 0deg));
  transform-origin: center center;
}

/* 横过来的那两个方向要把宽高换过来，转回去之后才正好铺满屏幕。
   基础规则里的 max-height: 100dvh 是给竖屏兜底封顶用的，横屏时视口本身的
   dvh 是短边，会把这里换算出来的 100dvw（长边）砍回 100dvh，铺满变成正方形——
   这两个属性必须在这里显式清掉，不能指望"后写的规则自动覆盖"，
   max-height 和 height 是两个不同属性，不会互相覆盖。 */
body.stage-swap #stage {
  width: 100dvh;
  height: 100dvw;
  max-width: none;
  max-height: none;
}

/* 画面转过去了，刘海和手势条也跟着换边：安全区按转后的方向重新对应 */
body.orient-90 {
  --safe-top: env(safe-area-inset-left, 0px);
  --safe-bottom: env(safe-area-inset-right, 0px);
}

body.orient-270 {
  --safe-top: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-left, 0px);
}

body.orient-180 {
  --safe-top: env(safe-area-inset-bottom, 0px);
  --safe-bottom: env(safe-area-inset-top, 0px);
}

/* 摇手机时整个画面震一下 */
/* 用单独的 translate 属性，不占 transform：transform 上挂着锁竖屏的旋转 */
@keyframes stage-shake {
  0%,
  100% {
    translate: 0 0;
  }
  20% {
    translate: -7px 3px;
  }
  40% {
    translate: 6px -4px;
  }
  60% {
    translate: -4px -4px;
  }
  80% {
    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;
}

/* 进来提示一次「建议开旋转锁定」，点一下关掉，不挡住杯子本体 */
.orientation-tip {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-3));
  left: 50%;
  z-index: 20;
  max-width: calc(100vw - var(--space-4) * 2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-chip);
  background: var(--color-panel-bg);
  color: var(--color-text);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 10px 30px rgba(59, 42, 30, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.orientation-tip.orientation-tip-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

/* ---- 加料面板：整页的图鉴 ---- */
/* 遮罩：点它就关掉面板 */
.codex-overlay {
  position: absolute;
  z-index: 10;
  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 {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: min(var(--codex-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 {
  display: grid;
  grid-template-columns: var(--codex-side) minmax(0, 1fr) var(--codex-side);
  align-items: center;
  min-height: 44px;
  margin-bottom: var(--space-2);
}

/* 标签一行：每个标签一样宽、平分整行，左右两边留一样多的空（右边的关闭按钮压在右边那一小块里），所以整排居中、间隙固定。
   窄到放不下才允许横着滑 */
.codex-tabs {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  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: 1 1 0;
  min-width: max-content;
  text-align: center;
  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%;
}

/* 英文标签长，字小一点、不加字距，一行放得下 */
:lang(en) .codex-tab {
  font-size: 12px;
  letter-spacing: 0;
}

:lang(en) .codex-card-name {
  font-size: 10px;
  line-height: 1.3;
}

/* 320 宽的窄屏：两边的空收窄一点，五个标签都能直接点到 */
@media (max-width: 359px) {
  :root {
    --codex-side: 32px;
  }

  .codex-tab {
    font-size: 13px;
    letter-spacing: 0.02em;
  }
}

.codex-close {
  grid-column: 3;
  justify-self: end;
  width: 44px;
  height: 44px;
  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 {
  flex: 1 1 auto;
  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-card.codex-card-static {
  pointer-events: none;
}

/* 图鉴里一款的图：第一口的截图，没喝到过的水滴也占同样大的格子，不让卡片跟着变高 */
.codex-card-recipe .codex-card-frame {
  width: 54px;
  height: 80px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--color-card-slot);
}

.codex-card-recipe .glyph-svg {
  width: 42px;
  height: 42px;
}

.codex-card-photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain; /* 整个杯子都要看得见，左右不裁 */
}

/* 图鉴里点开一款的小弹窗：盖在整个弹窗上，底色是实的 */
.codex-popup {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  border-radius: var(--radius-panel);
  background: rgba(59, 42, 30, 0.28);
}

.codex-popup[hidden] {
  display: none;
}

.codex-popup-card {
  width: 100%;
  max-width: 300px;
  padding: var(--space-3);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-panel);
  background: var(--color-panel-bg);
  text-align: center;
}

.codex-popup-title {
  margin: 0 0 var(--space-2);
  font-size: 17px;
  line-height: 1.4;
  color: var(--color-text);
}

.codex-needs {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.codex-need {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
}

.codex-need-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-2) 2px 4px;
  border-radius: var(--radius-button);
  background: var(--color-card-slot);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
}

.codex-need-chip .glyph-svg {
  width: 24px;
  height: 24px;
}

.codex-need-or {
  font-size: 12px;
  color: var(--color-text-soft);
}

.codex-add {
  padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-button);
  background: var(--color-accent);
  color: var(--color-panel-bg);
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0.08em;
}

/* 清空：工具页最下面的一个文本按钮 */
.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);
}

/* ---- 操作页底部的语言切换与作者信息（参考色鬼） ---- */
.pause-choice {
  margin: var(--space-4) auto 0;
  max-width: 280px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--color-card-slot);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pause-choice-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-soft);
  text-align: center;
  letter-spacing: 0.04em;
}

.pause-choice .lang-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pause-choice .lang-row button {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: var(--radius-button);
  background: var(--color-card-bg);
  border: 1px solid var(--line-soft);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pause-choice .lang-row button.primary {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
  font-weight: 700;
}

.kk-credit {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin: var(--space-3) auto var(--space-2);
  max-width: 280px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  line-height: 1.6;
  color: var(--color-text-soft);
  text-align: left;
}

.kk-credit-avatar {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
  background: var(--color-card-slot);
}

.kk-credit-text {
  min-width: 0;
  flex: 1;
  text-align: left;
}

.kk-credit-text p {
  margin: 0;
  text-align: left;
}

.kk-credit-link {
  display: inline;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---- 图标：描了粗边的图形，和画布上同一套勾线 ---- */
.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-mark {
  fill: var(--color-text-soft);
  stroke: none;
  font-size: 13px;
  font-weight: 600;
}

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

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