/* 小铁皮开锁 · 旧纸 + 黄铜 + 锈 的手绘界面 */
:root {
  --paper: #e9dcc0; --paper-dark: #cdbb96; --ink: #3a2a1c; --ink-soft: #6b5237;
  --brass: #c9a24a; --brass-dark: #8a6a24; --rust: #b4552b; --teal: #3f7d78; --teal-dark: #24514d;
  --red: #c0392b; --cream: #f6efdc;
  --shadow: 0 10px 30px rgba(40, 25, 10, .35);
  font-family: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255,255,255,.35), transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(120,70,20,.25), transparent 55%),
    repeating-linear-gradient(0deg, rgba(0,0,0,.025) 0 2px, transparent 2px 5px),
    var(--paper-bg, #d9c8a3);
  transition: background-color .8s ease;
  min-height: 100vh;
}
body.warning { animation: pulse-red 1.2s ease-in-out infinite; }
@keyframes pulse-red { 0%,100% { box-shadow: inset 0 0 0 0 rgba(192,57,43,0); } 50% { box-shadow: inset 0 0 120px 0 rgba(192,57,43,.45); } }

.app { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; max-width: 1500px; margin: 0 auto; padding: 16px; }
@media (max-width: 1100px) { .app { grid-template-columns: 1fr; } }

header.top { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo h1 { margin: 0; font-size: 28px; letter-spacing: 4px; font-weight: 700; color: var(--ink); text-shadow: 1px 1px 0 var(--cream); }
.logo .sub { font-size: 12px; color: var(--ink-soft); letter-spacing: 2px; }
.tools { display: flex; gap: 10px; align-items: center; }
.level-tag { font-size: 14px; color: var(--ink-soft); border: 1.5px solid var(--brass-dark); padding: 4px 10px; border-radius: 4px; background: var(--cream); box-shadow: 2px 2px 0 var(--brass-dark); }

/* 舞台 */
.stage-wrap { position: relative; background: var(--ink); padding: 10px; border: 6px solid var(--brass-dark); border-radius: 6px; box-shadow: var(--shadow), inset 0 0 0 2px var(--brass); }
.stage { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; background: #1c140d; border-radius: 3px; }
.stage img.frame, .stage video.clip { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage video.clip { opacity: 0; transition: opacity .5s ease; pointer-events: none; }
.stage video.clip.visible { opacity: 1; }
.stage .hot { position: absolute; cursor: pointer; border-radius: 6px; }
.stage .hot:hover { outline: 2px dashed rgba(201,162,74,.85); background: rgba(201,162,74,.12); }
.stage .hot .tip { position: absolute; left: 50%; top: -8px; transform: translate(-50%, -100%); white-space: nowrap; background: var(--cream); color: var(--ink); font-size: 13px; padding: 3px 8px; border: 1.5px solid var(--ink); border-radius: 3px; opacity: 0; pointer-events: none; transition: opacity .15s; }
.stage .hot:hover .tip { opacity: 1; }
.stage.dev .hot { outline: 1px solid rgba(255,0,0,.7); background: rgba(255,0,0,.08); }
.stage.dev .hot .tip { opacity: 1; }
.stage.item-selected { cursor: crosshair; }

/* 字幕气泡 */
.caption { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: 82%; background: var(--cream); color: var(--ink); font-size: 17px; line-height: 1.5; padding: 10px 16px; border: 2px solid var(--ink); border-radius: 14px; box-shadow: 3px 3px 0 var(--ink); opacity: 0; transition: opacity .25s; }
.caption.show { opacity: .97; }
.caption::after { content: ""; position: absolute; left: 30px; bottom: -10px; width: 14px; height: 14px; background: var(--cream); border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); }

/* 生成中：锅炉加压 */
.working { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px; background: rgba(28,20,13,.55); color: var(--cream); backdrop-filter: blur(2px); }
.working.show { display: flex; }
.working .gear { width: 74px; height: 74px; animation: spin 2.4s linear infinite; }
.working .gear.rev { animation-direction: reverse; width: 46px; height: 46px; margin-left: -18px; margin-top: -30px; }
@keyframes spin { to { transform: rotate(360deg); } }
.working .txt { font-size: 15px; letter-spacing: 2px; }
.working .sub { font-size: 12px; opacity: .8; }

/* 潜望镜小窗（回收机器人预警） */
.periscope { position: absolute; right: 14px; top: 14px; width: 26%; aspect-ratio: 16/9; border: 5px solid var(--brass-dark); border-radius: 50% / 40%; overflow: hidden; box-shadow: 0 0 0 3px var(--rust), 0 6px 18px rgba(0,0,0,.5); display: none; background: #000; }
.periscope.show { display: block; animation: shake .5s ease-in-out 3; }
.periscope video { width: 100%; height: 100%; object-fit: cover; }
.periscope .lbl { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; font-size: 12px; color: #ffd9d0; background: rgba(120,20,10,.7); padding: 2px; }
@keyframes shake { 0%,100% { transform: translate(0,0); } 25% { transform: translate(-4px,2px); } 75% { transform: translate(4px,-2px); } }

/* 底栏：道具 + 指令 */
.bottom { display: grid; grid-template-columns: auto 1fr; gap: 14px; margin-top: 14px; align-items: stretch; }
.inventory { display: flex; gap: 10px; padding: 8px 10px 26px; background: var(--paper-dark); border: 2px solid var(--brass-dark); border-radius: 6px; min-height: 84px; min-width: 120px; flex-wrap: wrap; max-width: 380px; }
.inventory .slot { width: 68px; height: 68px; border: 2px dashed var(--brass-dark); border-radius: 6px; background: var(--cream); display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.inventory .slot img { width: 92%; height: 92%; object-fit: contain; }
.inventory .slot.sel { outline: 3px solid var(--rust); background: #fff3d6; transform: translateY(-3px); }
.inventory .slot .nm { position: absolute; bottom: -19px; left: 50%; transform: translateX(-50%); font-size: 11px; white-space: nowrap; color: var(--ink-soft); max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.inventory .empty { align-self: center; color: var(--ink-soft); font-size: 13px; padding: 0 10px; }
.command { display: flex; flex-direction: column; gap: 6px; }
.command form { display: flex; gap: 8px; }
.command input { flex: 1; font: inherit; font-size: 16px; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 6px; background: var(--cream); color: var(--ink); }
.command button, .btn { font: inherit; font-size: 15px; padding: 8px 16px; border: 2px solid var(--ink); border-radius: 6px; background: var(--brass); color: var(--ink); cursor: pointer; box-shadow: 2px 2px 0 var(--ink); }
.command button:active, .btn:active { transform: translate(2px,2px); box-shadow: none; }
.btn.ghost { background: var(--cream); }
.btn.danger { background: var(--rust); color: #fff; }
.hintline { font-size: 12px; color: var(--ink-soft); }
.fishhint { display: none; font-size: 13px; line-height: 1.5; color: var(--cream, #f1e4c8); background: rgba(255, 170, 60, .08); border-left: 3px solid #e0902a; padding: 6px 10px; border-radius: 4px; }
.fishhint.show { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 9px; border: 1px solid var(--brass-dark); border-radius: 12px; background: var(--cream); cursor: pointer; }
.chip:hover { background: #fff3d6; }

/* 右栏 */
aside { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--cream); border: 2px solid var(--brass-dark); border-radius: 6px; padding: 12px; box-shadow: 3px 3px 0 var(--brass-dark); }
.panel h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: 2px; color: var(--ink-soft); border-bottom: 1px dashed var(--brass-dark); padding-bottom: 6px; }

/* 压力表倒计时 */
.gauge { display: flex; align-items: center; gap: 12px; }
.gauge svg { width: 110px; height: 110px; }
.gauge .num { font-size: 34px; font-weight: 700; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.gauge .num.warn { color: var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.gauge .st { font-size: 12px; color: var(--ink-soft); }

.clues { max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.clue { font-size: 13px; padding: 6px 8px; border: 1px solid var(--paper-dark); border-radius: 4px; background: #fffaf0; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
.clue.pinned { border-color: var(--rust); background: #ffe9d6; }
.clue .by { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }
.log { max-height: 200px; overflow: auto; font-size: 12px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }
.log .live { color: var(--teal-dark); }
.vote .opt { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 6px; border: 1px solid var(--paper-dark); border-radius: 4px; margin-bottom: 4px; }
.vote .bar { height: 6px; background: var(--brass); border-radius: 3px; }
.keyparts { display: flex; gap: 6px; }
.keyparts .kp { width: 34px; height: 34px; border: 2px solid var(--brass-dark); border-radius: 50%; background: var(--paper-dark); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--ink-soft); }
.keyparts .kp.got { background: var(--brass); color: var(--ink); }

/* 遮罩：开锁 / 通关 / 回收 */
.overlay { position: fixed; inset: 0; background: rgba(20,12,6,.72); display: none; align-items: center; justify-content: center; z-index: 50; }
.overlay.show { display: flex; }
.card { background: var(--paper); border: 4px solid var(--brass-dark); border-radius: 10px; padding: 22px; max-width: 760px; width: 92vw; box-shadow: var(--shadow); text-align: center; }
.card h2 { margin: 0 0 6px; letter-spacing: 4px; }
.card p { color: var(--ink-soft); margin: 6px 0 14px; }
.card canvas { display: block; margin: 0 auto 12px; background: #2a1e14; border: 3px solid var(--brass-dark); border-radius: 8px; touch-action: none; max-width: 100%; }
.card video { width: 100%; border-radius: 8px; border: 3px solid var(--rust); margin-bottom: 12px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.err { color: var(--red); font-size: 13px; }

/* 画面上的倒计时 HUD */
.hud { position: absolute; left: 14px; top: 14px; display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: rgba(28,20,13,.78); color: var(--cream); border: 2px solid var(--brass); border-radius: 8px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 2px; box-shadow: 0 3px 10px rgba(0,0,0,.4); z-index: 5; }
.hud .hud-ico { font-size: 18px; }
.hud .hud-st { font-size: 12px; font-weight: normal; letter-spacing: 1px; color: #ffe3b0; }
.hud.paused { border-color: #ffe3b0; background: rgba(60,45,20,.85); }
.hud.paused .hud-st::before { content: "⏸ "; }
.hud.warn { border-color: var(--red); color: #ffb3a7; animation: blink 1s steps(2) infinite; }

/* 危险感 */
.stage.shake { animation: stage-shake .45s ease-in-out; }
@keyframes stage-shake { 0%,100% { transform: translate(0,0); } 20% { transform: translate(-8px,4px); } 40% { transform: translate(7px,-5px); } 60% { transform: translate(-5px,3px); } 80% { transform: translate(4px,-2px); } }
body.flash .stage::after { content: ""; position: absolute; inset: 0; background: rgba(192,57,43,.35); pointer-events: none; animation: flash-out .5s ease-out forwards; }
@keyframes flash-out { to { opacity: 0; } }
.stage::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 4; box-shadow: inset 0 0 calc(40px + 160px * var(--danger, 0)) rgba(150, 20, 10, calc(0.55 * var(--danger, 0))); transition: box-shadow 1s linear; }

/* 开场短片 */
.overlay.intro { background: #0b0805; z-index: 60; }
.intro-box { position: relative; width: min(96vw, 1400px); aspect-ratio: 16/9; background: #000; border: 6px solid var(--brass-dark); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.intro-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.intro-cap { position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%); width: 92%; white-space: pre-line; text-wrap: balance; word-break: keep-all; font-size: clamp(14px, 1.7vw, 24px); line-height: 1.7; color: var(--cream); text-shadow: 0 2px 8px #000, 0 0 2px #000; text-align: center; letter-spacing: 1px; opacity: 0; transition: opacity .6s; }
.intro-cap.show { opacity: 1; }
.intro-title { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(11,8,5,.82); color: var(--cream); text-align: center; }
.intro-title.show { display: flex; animation: fadein 1.2s ease; }
.intro-title h1 { font-size: clamp(36px, 6vw, 88px); letter-spacing: 14px; margin: 0; color: var(--brass); text-shadow: 0 4px 20px #000; }
.intro-title div { font-size: clamp(14px, 1.6vw, 22px); letter-spacing: 3px; opacity: .85; }
.intro-skip { position: absolute; right: 16px; top: 14px; opacity: .8; }
/* 片头"点一下开始"层：浏览器不允许无手势的有声自动播放，被拒时出现 */
.intro-start { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(11,8,5,.88); color: var(--brass); cursor: pointer; text-align: center; }
.intro-start.show { display: flex; animation: fadein .6s ease; }
.intro-start span { font-size: clamp(18px, 2.6vw, 34px); letter-spacing: 4px; padding: 12px 26px; border: 2px solid var(--brass); border-radius: 8px; text-shadow: 0 2px 10px #000; }
.intro-start small { font-size: clamp(11px, 1.1vw, 15px); letter-spacing: 2px; color: var(--cream); opacity: .7; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ===== H5 手机排版（≤640px 才生效，PC/平板不受影响） ===== */
@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  .app { gap: 12px; padding: 10px 12px 24px; }

  /* 顶栏：第一行 = 图标 + 游戏名（一行）+ 右侧小音乐键；第二行 = 副标题；第三行 = 整幅关卡铜牌 */
  header.top { flex-wrap: wrap; align-items: flex-start; gap: 8px 10px; }
  .tools { display: contents; }
  .logo { flex: 1 1 0; min-width: 0; gap: 4px 9px; align-items: center; flex-wrap: wrap; }
  .logo svg { flex: 0 0 auto; width: 32px; height: 32px; }
  .logo > div { display: contents; }   /* 图标+游戏名同一行，副标题另起一行占满标题区宽度 */
  .logo .sub { flex: 1 1 100%; }
  .logo h1 { font-size: 20px; letter-spacing: 3px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .logo .sub { font-size: 11px; letter-spacing: 0; line-height: 1.5; margin-top: 3px; color: var(--ink-soft); }
  header.top #bgmBtn { order: 2; flex: 0 0 auto; align-self: flex-start; margin-top: 2px; white-space: nowrap; font-size: 12px; letter-spacing: 1px; padding: 5px 9px; border-width: 1.5px; box-shadow: 1.5px 1.5px 0 var(--ink); }
  .level-tag { order: 3; flex: 1 1 100%; width: 100%; font-size: 12px; line-height: 1.5; padding: 7px 12px 8px; text-align: center; border-radius: 4px; box-shadow: 2px 2px 0 var(--brass-dark); text-spacing-trim: trim-all; }
  .level-tag .lv-sep { display: none; }
  .level-tag .lv-name { font-weight: 700; letter-spacing: 1px; color: var(--brass-dark); white-space: nowrap; }
  .level-tag .lv-count { font-size: 11px; color: var(--brass-dark); opacity: .85; white-space: nowrap; }
  .level-tag .lv-desc { display: block; margin-top: 3px; line-height: 1.55; text-wrap: balance; }

  /* 舞台：边框收窄，HUD 与字幕气泡按小屏缩一档 */
  .stage-wrap { padding: 5px; border-width: 4px; border-radius: 5px; }
  .hud { left: 8px; top: 8px; padding: 4px 9px; font-size: 15px; letter-spacing: 1px; gap: 6px; border-width: 1.5px; border-radius: 6px; }
  .hud .hud-ico { font-size: 13px; }
  .hud .hud-st { font-size: 10px; letter-spacing: 0; }
  .caption { max-width: 90%; bottom: 8px; font-size: 14px; line-height: 1.5; padding: 7px 12px; border-width: 1.5px; border-radius: 10px; box-shadow: 2px 2px 0 var(--ink); }
  .caption::after { left: 20px; bottom: -8px; width: 11px; height: 11px; border-width: 1.5px; }
  .stage .hot .tip { font-size: 12px; }
  .working .gear { width: 56px; height: 56px; }
  .working .gear.rev { width: 36px; height: 36px; margin-left: -14px; margin-top: -24px; }
  .working .txt { font-size: 14px; letter-spacing: 1px; }
  .working .sub { font-size: 11px; padding: 0 18px; text-align: center; line-height: 1.5; }
  .periscope { right: 8px; top: 8px; width: 30%; border-width: 3px; }
  .periscope .lbl { font-size: 10px; }

  /* 底栏：道具栏与输入区上下叠放；空道具栏收成一条虚线窄条 */
  .bottom { grid-template-columns: 1fr; gap: 10px; margin-top: 10px; }
  .inventory { max-width: none; min-height: 0; min-width: 0; padding: 8px 10px 22px; gap: 8px; }
  .inventory .slot { width: 56px; height: 56px; }
  .inventory .slot .nm { bottom: -17px; font-size: 10px; }
  .inventory:not(:has(.slot)) { padding: 7px 10px; justify-content: center; border-style: dashed; background: transparent; }
  .inventory .empty { font-size: 12px; letter-spacing: 2px; padding: 0; }
  .command { gap: 8px; }
  .command form { gap: 6px; }
  .command input { min-width: 0; padding: 9px 10px; border-width: 1.5px; }
  .command input::placeholder { font-size: 14px; }
  .command form button { flex: 0 0 auto; white-space: nowrap; font-size: 14px; letter-spacing: 1px; padding: 8px 12px; border-width: 1.5px; }
  .chips { gap: 7px; }
  .chip { font-size: 12px; padding: 5px 11px; }
  .fishhint { font-size: 13px; line-height: 1.55; color: var(--ink); background: rgba(224, 144, 42, .14); padding: 7px 10px; }
  .hintline { font-size: 11px; line-height: 1.55; opacity: .85; }

  /* 右栏（手机上落到底部）：压缩成小卡片 */
  aside { gap: 10px; }
  .panel { padding: 10px 12px; box-shadow: 2px 2px 0 var(--brass-dark); }
  .panel h3 { font-size: 13px; letter-spacing: 2px; margin-bottom: 8px; }
  .gauge { gap: 14px; }
  .gauge svg { width: 72px; height: 72px; }
  .gauge .num { font-size: 26px; line-height: 1.1; }
  .gauge .st { font-size: 11px; }
  .keyparts { justify-content: space-between; }
  .keyparts .kp { width: 36px; height: 36px; font-size: 11px; }
  .log { max-height: 150px; font-size: 12px; }
  .panel .row .btn { font-size: 13px; padding: 6px 12px; }

  /* 弹层与开场 */
  .card { padding: 16px 12px; width: 94vw; border-width: 3px; }
  .card h2 { font-size: 20px; letter-spacing: 3px; }
  .card p { font-size: 14px; line-height: 1.55; }
  .card .btn { font-size: 14px; }
  .intro-cap { font-size: 13px; line-height: 1.55; width: 94%; letter-spacing: 0; }
  .intro-title { gap: 8px; }
  .intro-title h1 { letter-spacing: 8px; }
  .intro-title div { font-size: 12px; letter-spacing: 1px; padding: 0 12px; }
  .intro-skip { right: 8px; top: 8px; font-size: 13px; padding: 5px 10px; }
}
