/* 毛线搭子 · 夜里纸箱里的一根线 */
:root {
  --ink: #0b111b;
  --ink2: #101a26;
  --card: #16202d;
  --line: #263448;
  --line2: #33465f;
  --txt: #e9eff8;
  --dim: #8ea4bf;
  --orange: #ff9d52;
  --teal: #4fd8d0;
  /* 房主黄、加入者蓝 */
  --cat0: #ffc93c;
  --cat0-dim: rgba(255, 201, 60, .34);
  --cat1: #4d8dff;
  --cat1-dim: rgba(77, 141, 255, .34);
  --yarn: #f0e4cd;
  --warn: #ff7a6b;
  --r: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--txt);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 520px at 18% -12%, #1b2a3d 0%, transparent 62%),
    radial-gradient(900px 460px at 88% 108%, #182434 0%, transparent 60%),
    var(--ink);
}

/* ---------------- 顶栏 ---------------- */
.hud {
  flex: 0 0 auto;
  height: 46px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(38, 52, 72, .8);
  background: rgba(11, 17, 27, .55);
  backdrop-filter: blur(6px);
}

.hud-l { display: flex; align-items: center; gap: 10px; min-width: 0; }

.lvtag {
  font-size: 13px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lvtag b { color: var(--txt); font-size: 15px; font-weight: 700; margin: 0 1px; }
.lvsep { margin: 0 2px; opacity: .45; }

.track {
  width: 74px;
  height: 4px;
  border-radius: 3px;
  background: #1d2836;
  overflow: hidden;
  flex: 0 0 auto;
}
.track i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--orange), #ffc48a);
  transition: width .35s cubic-bezier(.2, .8, .3, 1);
}

.hud-mid {
  flex: 1 1 auto;
  text-align: center;
  font-size: 12.5px;
  color: var(--dim);
  letter-spacing: .2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-r { display: flex; gap: 6px; flex: 0 0 auto; }

.icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #17222f;
  color: var(--dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: .18s;
}
.icon:hover { color: var(--txt); border-color: var(--line2); background: #1d2a3a; }
.icon.off { color: #5b6d84; text-decoration: line-through; }

/* ---------------- 舞台 ---------------- */
.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

#cv {
  display: block;
  border-radius: 10px;
  background: #0a0f18;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, .9), 0 0 0 1px rgba(52, 70, 95, .5);
}

.toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -14px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(16, 26, 38, .94);
  border: 1px solid var(--line2);
  color: var(--txt);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .28s ease;
  white-space: nowrap;
  z-index: 8;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.clearflash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(60% 60% at 50% 50%, rgba(240, 228, 205, .3), transparent 70%);
  transition: opacity .45s ease;
  z-index: 7;
}
.clearflash.on { opacity: 1; transition: opacity .12s ease; }

/* ---------------- 虚拟按键 ---------------- */
.pads { display: none; }

/* 触屏：JS 检测到触摸就在 body 上加 .touch（比纯媒体查询可靠） */
body.touch .pads,
body.touch .pads.show {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px calc(10px + env(safe-area-inset-bottom));
}
body.touch .keyhint { display: none !important; }

@media (pointer: coarse) {
  .pads {
    flex: 0 0 auto;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .keyhint { display: none !important; }
}

.pad {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 260px;
}
.pad[data-p="1"] { align-items: stretch; }

.prow { display: flex; gap: 6px; }
.prow:first-child { justify-content: center; }

.k {
  flex: 1 1 0;
  height: 52px;
  border-radius: 13px;
  border: 1px solid var(--line2);
  background: #1a2635;
  color: var(--txt);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .5px;
  cursor: pointer;
  transition: transform .06s, background .12s;
  touch-action: none;
}
.k-jump { flex: 0 0 46%; background: #1e2c3d; }
.k-pull { flex: 1.3 1 0; color: var(--yarn); background: #22303f; }
.pad[data-p="0"] .k { border-color: var(--cat0-dim); }
.pad[data-p="1"] .k { border-color: var(--cat1-dim); }
.pad[data-p="0"] .k.on { background: #3a3117; border-color: var(--cat0); color: var(--cat0); transform: scale(.96); }
.pad[data-p="1"] .k.on { background: #161f36; border-color: var(--cat1); color: var(--cat1); transform: scale(.96); }

/* ---- JS class 版本（真机与模拟器一致） ---- */
/* 横屏：按键做成画面下方的独立条带，不压住关卡 */
body.touch.landscape .stage {
  flex: 1 1 auto;
  padding: 0 6px;
  min-height: 0;
}
body.touch.landscape .pads {
  position: static;
  flex: 0 0 auto;
  height: 62px;
  padding: 0 10px calc(4px + env(safe-area-inset-bottom));
  pointer-events: auto;
  align-items: center;
  gap: 14px;
}
/* 横屏横向空间够，两组键都摊成一行，省高度给画面 */
body.touch.landscape .pad {
  flex: 1 1 0;
  flex-direction: row;
  align-items: center;
  max-width: none;
  opacity: .95;
  gap: 7px;
}
body.touch.landscape .prow { flex: 1 1 auto; gap: 7px; }
body.touch.landscape .prow:first-child { flex: 0 0 21%; justify-content: stretch; }
body.touch.landscape .prow:last-child { flex: 1 1 auto; }
body.touch.landscape .k {
  height: 50px;
  min-width: 44px;
  font-size: 14px;
  background: rgba(26, 38, 53, .92);
  border-width: 1.5px;
}
body.touch.landscape .k-jump { flex: 1 1 auto; width: 100%; }
body.touch.landscape .k-pull { flex: 1.4 1 0; }
body.touch.landscape .k-jump { flex: 0 0 40%; }

body.touch.portrait .stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 3% 0;   /* 左右各留 3%，其余全给画面 */
}
body.touch.portrait .pads {
  flex: 0 0 auto;     /* 高度由内容定死，别跟画布抢空间 */
  padding: 12px 10px calc(16px + env(safe-area-inset-bottom));
}
body.touch.portrait .k { height: min(17vh, 84px); font-size: 17px; }

/* 竖屏横幅提示：横过来画面大得多 */
.tilt-tip {
  display: none;
  flex: 0 0 auto;
  text-align: center;
  font-size: 12.5px;
  color: var(--dim, #7c8b9e);
  padding: 10px 0 0;
  letter-spacing: .02em;
}
body.touch.portrait .tilt-tip { display: block; }
body.touch.portrait .k-jump { flex: 0 0 42%; }

/* ---------------- 键盘提示 ---------------- */
.keyhint {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12.5px;
  color: var(--dim);
  border-top: 1px solid rgba(38, 52, 72, .7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.keyhint .who { font-weight: 700; margin: 0 4px; }
.keyhint .who.one { color: var(--cat0); }
.keyhint .who.two { color: var(--cat1); }
.keyhint .dot { margin: 0 10px; opacity: .4; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid var(--line2);
  background: #16202d;
  font-family: inherit;
  font-size: 11.5px;
  color: #c9d7e8;
  line-height: 1.5;
}

/* ---------------- 覆盖层 ---------------- */
.veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(720px 420px at 50% 8%, rgba(255, 157, 82, .07), transparent 65%),
    rgba(8, 13, 20, .9);
  backdrop-filter: blur(9px);
  overflow-y: auto;
  transition: opacity .3s ease, visibility .3s;
}
.veil.hide { opacity: 0; visibility: hidden; pointer-events: none; }

.panel {
  width: 100%;
  max-width: 380px;
  margin: auto;
  animation: rise .34s cubic-bezier(.2, .85, .3, 1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.logo {
  margin: 0 0 6px;
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.05;
  background: linear-gradient(100deg, var(--orange) 8%, var(--yarn) 52%, var(--teal) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  margin: 0 0 22px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--dim);
}

.field { display: block; margin-bottom: 12px; }
.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: .3px;
}

input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #131d29;
  color: var(--txt);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .18s, background .18s;
}
input::placeholder { color: #5f7085; }
input:focus { border-color: var(--line2); background: #16212f; }

.big {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: .5px;
  cursor: pointer;
  transition: transform .07s, filter .18s, border-color .18s;
  border: 1px solid transparent;
}
.big:active { transform: scale(.985); }

.big.main {
  background: linear-gradient(180deg, #ffab68, var(--orange));
  color: #23150a;
  box-shadow: 0 10px 26px -12px rgba(255, 157, 82, .8);
}
.big.main:hover { filter: brightness(1.06); }

.big.ghost {
  background: #17222f;
  border-color: var(--line2);
  color: var(--txt);
}
.big.ghost:hover { background: #1d2a3a; }

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  font-size: 11.5px;
  color: #5d7189;
}
.or i { flex: 1; height: 1px; background: var(--line); }

.joinrow { display: flex; gap: 8px; }
.joinrow input {
  flex: 1 1 auto;
  height: 48px;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding: 0 10px;
}
.joinrow .big { flex: 0 0 96px; }

.tiny {
  margin: 18px 0 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: #63768d;
}
.tiny.err { color: var(--warn); }

/* 房间面板 */
.roofline {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--dim);
  text-align: center;
}

.codebox {
  display: flex;
  justify-content: center;
  padding: 22px 0;
  border-radius: var(--r);
  border: 1px dashed var(--line2);
  background: #121b26;
}
.codebox span {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 10px;
  text-indent: 10px;
  color: var(--yarn);
  font-variant-numeric: tabular-nums;
}

.copy {
  width: 100%;
  height: 40px;
  margin-top: 10px;
  border-radius: 11px;
  border: 1px solid var(--line2);
  background: transparent;
  color: var(--dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: .18s;
}
.copy:hover { color: var(--txt); background: #17222f; }

.waitrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 22px 0 18px;
  font-size: 13px;
  color: var(--dim);
}
.blip {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 0 rgba(255, 157, 82, .5);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 157, 82, .5); }
  70% { box-shadow: 0 0 0 9px rgba(255, 157, 82, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 157, 82, 0); }
}

.link {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  border: 0;
  background: none;
  color: #62758c;
  font-size: 12.5px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--dim); }

/* 菜单 */
.mtitle {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .5px;
}

.mrow {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 11px 0;
  border-bottom: 1px solid rgba(38, 52, 72, .65);
  font-size: 13.5px;
  color: var(--dim);
}
.mrow b { color: var(--txt); font-weight: 600; font-variant-numeric: tabular-nums; }
.mrow:last-of-type { margin-bottom: 22px; }

/* 旋转提示 */
.rotate-tip {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 8px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(22, 32, 45, .95);
  border: 1px solid var(--line2);
  font-size: 12px;
  color: var(--dim);
  opacity: 0;
  pointer-events: none;
  transition: .35s ease;
  z-index: 15;
}
.rotate-tip.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 480px) {
  .hud { height: 38px; }
  .keyhint { display: none; }
  .logo { font-size: 30px; }
  .sub { margin-bottom: 14px; }
}


/* ---------------- 联机时只留自己那组键 ---------------- */
body.net.me0 .pad[data-p="1"] { display: none; }
body.net.me1 .pad[data-p="0"] { display: none; }
body.net.me0 .pad[data-p="0"],
body.net.me1 .pad[data-p="1"] { max-width: none; width: 100%; }
body.net .pads { justify-content: stretch; }

/* ---------------- 横屏引导层 ---------------- */
.rotgate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: radial-gradient(circle at 50% 38%, #16222f 0%, #080d14 70%);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.touch.portrait.gate .rotgate { display: flex; }
.rotgate-in { text-align: center; max-width: 320px; }
.rot-icon {
  font-size: 46px;
  line-height: 1;
  color: var(--cat0);
  margin-bottom: 16px;
  animation: rotspin 2.6s ease-in-out infinite;
}
@keyframes rotspin {
  0%, 42% { transform: rotate(0deg); }
  58%, 100% { transform: rotate(-90deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rot-icon { animation: none; }
}
.rot-title {
  font-size: 21px;
  font-weight: 600;
  margin: 0 0 8px;
  color: #eaf1f8;
}
.rot-sub {
  font-size: 13.5px;
  color: #7f8fa3;
  margin: 0 0 22px;
  line-height: 1.6;
}
.rotgate .big { width: 100%; }

/* 菜单里的房主按钮区 */
#hostBox { display: flex; flex-direction: column; gap: 8px; }
#hostBox[hidden] { display: none; }

.copy.alt {
  margin-top: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .18);
  color: #cfd8e8;
  font-size: 13px;
  letter-spacing: .04em;
}
.copy.alt:hover { border-color: rgba(255, 255, 255, .34); }
