:root {
  --bg: #0a0a10;
  --panel: #14141c;
  --line: #2a2a38;
  --text: #e8e8f0;
  --dim: #8a8a9c;
  --gold: #f4d43a;
  --red: #e04040;
  --blue: #4a8ef0;
  --green: #40d060;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(ellipse at 50% -10%, #1b1b2a 0%, transparent 60%),
    repeating-linear-gradient(0deg, #0c0c12 0 2px, #0a0a10 2px 4px);
  min-height: 100vh;
}

.app {
  max-width: 940px;
  margin: 0 auto;
  padding: 14px 12px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 0 #7a5f00;
}
.topbar h1 span {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 4px;
  margin-left: 8px;
}

.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  background: #1c1c28;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
  font-family: inherit;
}
.btn:hover { background: #262636; border-color: #3c3c52; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: #7a2020; border-color: #a03030; color: #ffe9c0; font-weight: 600; }
.btn.primary:hover { background: #962a2a; }
.btn.on { background: #1d4a2a; border-color: #2f7a44; color: #b6f5c8; }

.stage-wrap { display: flex; justify-content: center; padding: 16px 0 8px; }

.screen {
  position: relative;
  line-height: 0;
  border: 2px solid #2c2c3c;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 4px #0d0d14, 0 18px 50px rgba(0, 0, 0, .75);
  background: #000;
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: min(816px, calc(100vw - 48px));
  height: auto;
  touch-action: none;
}

.layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 4, 8, .88);
  backdrop-filter: blur(2px);
  line-height: 1.6;
  padding: 12px;
}
.layer.hidden { display: none; }

.panelbox {
  text-align: center;
  max-width: 560px;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 16, 24, .92);
}
.panelbox h2 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 2px 0 #6a5200;
}
.panelbox .sub { color: var(--dim); font-size: 12px; letter-spacing: 1px; }
.panelbox .hint { color: #b9b9cc; font-size: 12.5px; margin: 6px 0; }
.panelbox .hint.tiny { color: #6a6a80; font-size: 11px; }

.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  margin: 14px auto 10px;
  max-width: 420px;
}
.stage {
  aspect-ratio: 1;
  background: #1e1e2c;
  border: 1px solid #34344a;
  color: var(--text);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background .1s;
}
.stage:hover:not(.locked) { background: #7a2020; border-color: #a03030; color: #ffe9c0; }
.stage.locked { opacity: .28; cursor: not-allowed; }

.toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, -6px);
  padding: 6px 18px;
  background: rgba(8, 8, 14, .9);
  border: 1px solid #3a3a50;
  border-radius: 4px;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  line-height: 1.5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ 触屏 */

.touch-ui {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 4px 0;
  user-select: none;
  -webkit-user-select: none;
}

/* 只要是触屏设备 / 窄屏就出按键，别只靠 ontouchstart 猜 */
body.touch .touch-ui { display: flex; }
@media (pointer: coarse) { .touch-ui { display: flex; } }
@media (max-width: 720px) { .touch-ui { display: flex; } }

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  width: min(46vw, 210px);
  aspect-ratio: 1;
  flex: 0 0 auto;
}
.pad button {
  background: #22222f;
  border: 1px solid #3a3a50;
  color: #dcdce8;
  border-radius: 12px;
  font-size: 20px;
  touch-action: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background .08s, transform .05s;
}
.pad button.on { background: #8a2626; border-color: #c04040; color: #fff0d0; }
.pad button:active { transform: scale(.94); }
.pad .u { grid-area: 1 / 2; }
.pad .l { grid-area: 2 / 1; }
.pad .d { grid-area: 3 / 2; }
.pad .r { grid-area: 2 / 3; }

#btn-fire {
  width: min(30vw, 132px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #7a2020;
  border: 2px solid #a03030;
  color: #ffe9c0;
  font-size: clamp(15px, 4.4vw, 20px);
  font-weight: 700;
  touch-action: none;
  font-family: inherit;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background .08s, transform .05s;
}
#btn-fire.on { background: #b03030; }
#btn-fire:active { transform: scale(.95); }

/* ------------------------------------------------------------ 说明区 */

.legend-wrap { margin-top: 16px; }
.legend-wrap > summary {
  display: none;
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 1px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
}
.legend-wrap > summary::-webkit-details-marker { display: none; }
.legend-wrap > summary em {
  font-style: normal;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0;
}
/* 只在 JS 判定为触屏（也就是真的把说明折叠起来了）时才显示这个把手 */
body.touch .legend-wrap > summary { display: flex; }
.legend-wrap[open] > summary em { visibility: hidden; }

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.legend-col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
}
.legend-col h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
}
.legend-col ul { margin: 0; padding-left: 16px; }
.legend-col li { font-size: 12px; color: #b0b0c4; line-height: 1.9; }
.legend-col b { color: #e8e8f0; }

.sw {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 6px;
  vertical-align: -1px;
  border-radius: 2px;
}
.sw.brick { background: #b0413c; }
.sw.steel { background: #9aa5b1; }
.sw.water { background: #2040a0; }
.sw.tree { background: #1f8a3c; }
.sw.ice { background: #8fd0e8; }

/* ------------------------------------------------------------ 触屏 */
/* （触屏区已移到说明区上方，见文件前半部分） */

@media (max-width: 720px) {
  /* 窄屏优先保证「画面 + 按键」一屏装得下，顶栏能压多扁压多扁 */
  .topbar { padding-bottom: 8px; gap: 8px; }
  .topbar h1 { font-size: 15px; letter-spacing: 1px; }
  .topbar h1 span { display: none; }
  .btns { gap: 6px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  #game { width: calc(100vw - 32px); }
  .grid { grid-template-columns: repeat(10, 1fr); }
  .stage-wrap { padding: 12px 0 4px; }
  .app { padding: 10px 10px 32px; }
  .legend { grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
  .legend-col li { line-height: 1.75; }
}
