/* ---------------------------------------------------------
   Run —— 页面外框样式
   只负责页面外框：本次把 Canvas 放大成页面主体、移动端尽量占满屏幕。
   Canvas 内部逻辑分辨率仍是 960 x 320，这里只改 CSS 显示尺寸与布局。
   --------------------------------------------------------- */

:root {
  --accent: #d95d2a;
  --frame: #2b2b2b;
  --shell: #14131a;                        /* 深色游戏外壳底色 */
  --shell-line: rgba(255, 255, 255, 0.05); /* 极淡的像素格纹 */
  --shell-text: #d8d2c2;
  --stage-max: 1280px;                     /* 桌面端上限：不再是小 Demo 尺寸 */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;                      /* 手机：跟随动态视口高度 */
  padding:
    max(10px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;

  color: var(--shell-text);
  font-family: "Courier New", Courier, ui-monospace, monospace;
  letter-spacing: 0.02em;

  background-color: var(--shell);
  /* 深色外壳 + 极淡格纹：只作外围，不再占据视觉主体 */
  background-image:
    linear-gradient(to right, var(--shell-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--shell-line) 1px, transparent 1px);
  background-size: 18px 18px;

  overflow-x: hidden;
  overscroll-behavior: none;               /* 游戏区域之外也不触发下拉刷新 */
  touch-action: none;                      /* 整页当作游戏外框：不滚动、不缩放 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: 100%;
  max-width: var(--stage-max);             /* 桌面端尽量撑满，只留外壳边距 */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.head {
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(16px, 2.4vw, 26px);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  color: var(--shell-text);
  text-shadow: 2px 2px 0 rgba(217, 93, 42, 0.35);
}

.title::before {
  content: ">";
  color: var(--accent);
  margin-right: 6px;
}

.stage {
  position: relative;
  width: 100%;
  border: 4px solid var(--frame);
  /* 硬阴影，模拟老式掌机的厚边框 */
  box-shadow:
    0 0 0 4px rgba(0, 0, 0, 0.35),
    10px 10px 0 rgba(0, 0, 0, 0.35);
  background: #fbf8f0;
  overflow: hidden;
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;             /* 按 960:320 原始比例自动算高度，不变形 */
  /* 放大时保持像素边缘锐利 */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;       /* 游戏区域不滚动、不缩放、不双击放大 */
  cursor: pointer;
}

/* 手机竖屏 / 横屏矮视口：几乎满宽，压缩外壳留白 */
@media (max-width: 600px), (max-height: 520px) {
  body {
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    gap: 6px;
  }

  .app {
    max-width: none;
    gap: 6px;
  }

  .title {
    font-size: clamp(14px, 4vw, 20px);
  }

  .stage {
    border-width: 3px;
    box-shadow:
      0 0 0 3px rgba(0, 0, 0, 0.35),
      6px 6px 0 rgba(0, 0, 0, 0.35);
  }
}
