:root{
  --cream:#f7f4ef;
  --ink:#222;
  --muted:#666;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---- 全局：盒模型与基础 ---- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  overflow: hidden;            /* 页面根不滚动，滚动交给 xterm */
  /* overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  touch-action: manipulation; */
    overscroll-behavior-y: none; /* 纵向不把 overscroll 传给外面（如浏览器 UI） */
  /* 不在根节点限制 touch-action，交给具体滚动容器去控制 */
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- 主容器：纵向布局，吃掉剩余高度 ---- */
#app {
  margin: 0 auto;
  padding: 0px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;

  width: 100%;      /* ★ 新增：宽度固定占满父容器 */
  max-width: 100%;  /* ★ 防止被内容撑得更宽 */
}

/* ---- 提示区：移到左上角，体积小，不考虑刘海 ---- */
#status {
  order: 0;
  align-self: flex-start;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
  font-family: var(--mono);
  margin-bottom: 8px;
}

/* ---- 终端包裹层：填满剩余高度 ---- */
#terminal {
  order: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fffefb;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
  padding: 8px;

  display: flex;        /* 让内部 #term 可以 flex:1 */
  flex: 1 1 auto;       /* 占据 #app 的剩余空间 */
  min-height: 0;        /* 避免子项撑高 */
  overflow: hidden;     /* 终端内部滚动由 xterm 控制 */
}

/* ---- xterm 容器链路：必要且足够 ---- */
#term {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

#term .xterm {
  width: 100%;
 height: 100%;   /* 容器本身铺满 #term 即可 */
}

/* 屏幕层铺满容器，交给官方 CSS 控制 viewport 布局 */
#term .xterm-screen {
  width: 100%;
  height: 100%;
}

/* rows 不要强制 100% 高度，让它按内容自然撑高，供 viewport 滚动 */
#term .xterm-rows {
  width: 100%;
}

/* viewport 高度交给 xterm.css 自己通过 top/bottom 约束，不要强压 height:100% */
#term .xterm-viewport {
  width: 100%;
}

/* 恢复 xterm 原生滚动，由其自身 viewport 控制 */
#term .xterm-viewport {
  overflow-y: auto;                 /* 明确只纵向滚 */
  overscroll-behavior-y: contain;   /* 滚动不传到页面 */
  touch-action: pan-y;              /* 手势识别为纵向滚动 */
  -webkit-overflow-scrolling: touch;/* iOS 惯性滚动 */
  scrollbar-gutter: stable both-edges;
}

/* ---- 底部栏（底部 #titlebar） ---- */
#titlebar {
  order: 3;                         /* 放在末尾即“底部” */
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;                  /* 与内容留出间距 */
  flex: 0 0 auto;
  background: var(--cream);
  z-index: 10;

  /* 采用 sticky + bottom，若父级产生滚动则吸附底边；
     若无滚动（当前布局），其表现等同常规流式布局在底部 */
  position: sticky;
  bottom: constant(safe-area-inset-bottom);
  bottom: env(safe-area-inset-bottom);
}

/* 左侧占位：保持第一个 span 左对齐，其余靠右 */
#titlebar > span:first-child { margin-right: auto; }

/* ---- 页脚 ---- */
footer {
  order: 4;
  flex: 0 0 auto;
  text-align: center;
  padding: 6px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
  margin: 0;
}

footer a {
  color: inherit;
  text-decoration: none;
  display: block;
}
footer a:hover,
footer a:focus { text-decoration: underline; }

/* ---- 小屏进一步压缩内边距 ---- */
@media (max-height: 500px) {
  #app { padding: 8px; }
  #terminal { padding: 6px; }
  footer { padding: 4px 0; }
}

/* PC端（示例按 1024px 以上作为“PC”阈值） */
@media (min-width: 1024px) {
  #app {
    width: 50vw;
    max-width: none;
  }
}


/* ===== WASM 加载屏 ===== */

#wasm-loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Mono",
               "Menlo", "Courier New", monospace;
  color: #000000;
}

/* 类似老游戏的像素框感：多重描边 + 方角 */
.wasm-loader-frame {
  min-width: 260px;
  max-width: 360px;
  padding: 20px 24px 18px;
  background: #ffffff;
  border: 2px solid #000;
  box-shadow:
    0 0 0 2px #000,
    0 0 0 4px #000; /* 多层描边，做一点“像素边框”的味道 */
  text-align: center;
}

.wasm-loader-title {
  font-size: 24px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 18px;
  text-shadow: 1px 1px 0 #000;
}

/* 包裹层，用来居中整个进度条 */
.wasm-loader-bar-shell {
  margin: 0 auto 12px;
}

/* 外框：白底+黑边，保持像素风 */
.wasm-loader-bar-track {
  position: relative;
  width: 220px;
  height: 12px;
  margin: 0 auto;
  border: 2px solid #000;
  background: #ffffff;
  overflow: hidden;
}

/*
  内部真正的动画条：
  - 黑色方条
  - 用 transform 做左右滑动，避免 width 突然归零产生“跳变”
*/
.wasm-loader-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;              /* 条本身宽度 */
  background: #000000;
  image-rendering: pixelated;
  animation: wasm-loader-slide 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

/* 丝滑滑动：从左边外侧滑到右边外侧，再循环 */
@keyframes wasm-loader-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(230%);
  }
}

.wasm-loader-sub {
  font-size: 12px;
  margin-bottom: 4px;
}

.wasm-loader-hint {
  font-size: 10px;
  color: #555;
  opacity: 0.85;
}

/* 当 WASM ready 时，我们会加上 .hidden 类隐藏加载层 */
#wasm-loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}
