:root {
  --ink: #111317;
  --ink-2: #181b20;
  --ink-3: #20242b;
  --line: #2e333c;
  --line-2: #3b414c;
  --sand: #e9e1cb;
  --amber: #f5b82e;
  --amber-deep: #d6930b;
  --text: #ece8dd;
  --muted: #8a8f99;
  --red: #ef4b3f;
  --display: "Bahnschrift SemiBold Condensed", "Bahnschrift Condensed", "Bahnschrift", "DIN Condensed", "DIN Alternate", "Arial Narrow", "Microsoft YaHei UI", sans-serif;
  --body: "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(1200px 700px at 70% 20%, #1c2027 0%, var(--ink) 60%) fixed;
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--amber); color: #111; }

#bgCanvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.grain {
  position: fixed; inset: -50%; z-index: 1; pointer-events: none; opacity: .07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -4%); }
  60% { transform: translate(-4%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

/* ======================= 大厅 ======================= */
#lobby {
  position: relative; z-index: 2; height: 100%;
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, 420px);
  gap: clamp(32px, 6vw, 110px); align-items: center;
  padding: 0 clamp(28px, 7vw, 130px);
}
.hero > * { opacity: 0; animation: rise .8s cubic-bezier(.2, .8, .2, 1) forwards; }
.hero > :nth-child(1) { animation-delay: .05s; }
.hero > :nth-child(2) { animation-delay: .15s; }
.hero > :nth-child(3) { animation-delay: .3s; }
.hero > :nth-child(4) { animation-delay: .42s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.tag {
  display: inline-flex; align-items: center; gap: 10px;
  font: 600 13px/1 var(--display); letter-spacing: .28em; color: var(--amber);
  border: 1px solid rgba(245, 184, 46, .35); padding: 8px 12px 7px; border-radius: 2px;
}
.tag .dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 10px #4ade80; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.title { margin: 22px 0 18px; line-height: .82; }
.t-en {
  display: block; font-family: var(--display); font-weight: 700;
  font-size: clamp(88px, 13vw, 200px); letter-spacing: -.01em; text-transform: uppercase;
  color: var(--text);
  background: linear-gradient(180deg, #f6f1e4 0%, #cfc6ae 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .55));
}
.t-cn {
  display: inline-block; margin-top: 18px; font-family: var(--body); font-weight: 900;
  font-size: clamp(22px, 2.6vw, 34px); letter-spacing: .5em; color: #111;
  background: var(--amber); padding: 8px 6px 8px 18px;
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
}
.lead { font-size: 17px; line-height: 1.75; color: #b9b5aa; margin: 0 0 30px; max-width: 30em; }
.lead em { font-style: normal; color: var(--amber); border-bottom: 2px dashed var(--amber); }
.rules { list-style: none; padding: 0; margin: 0; display: flex; gap: 14px; flex-wrap: wrap; }
.rules li {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px 12px 12px;
  background: rgba(255, 255, 255, .03); border: 1px solid var(--line); border-radius: 3px;
}
.rules b { font: 700 26px/1 var(--display); color: var(--amber); min-width: 38px; text-align: center; }
.rules span { font-size: 13px; color: #a7a499; }

.console {
  position: relative; background: linear-gradient(180deg, rgba(32, 36, 43, .92), rgba(22, 25, 30, .95));
  border: 1px solid var(--line-2); border-radius: 4px; padding: 26px 26px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .05);
  backdrop-filter: blur(6px);
  opacity: 0; animation: rise .9s .25s cubic-bezier(.2, .8, .2, 1) forwards;
}
.console::before {
  content: ""; position: absolute; left: -1px; right: -1px; top: -1px; height: 6px; border-radius: 4px 4px 0 0;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 10px, #111 10px 20px);
}
.console::after {
  content: ""; position: absolute; inset: 10px; pointer-events: none;
  background:
    linear-gradient(var(--amber), var(--amber)) top left / 14px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) top left / 2px 14px no-repeat,
    linear-gradient(var(--amber), var(--amber)) bottom right / 14px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) bottom right / 2px 14px no-repeat;
  opacity: .5;
}
.console-head {
  display: flex; justify-content: space-between; margin: 4px 0 22px;
  font: 600 13px/1 var(--display); letter-spacing: .3em; color: var(--muted);
}
.console-head .serial i { font-style: normal; color: var(--text); font-family: var(--mono); letter-spacing: .05em; }

.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font: 600 12px/1 var(--display); letter-spacing: .2em; color: var(--muted); margin-bottom: 8px; }
.field input {
  width: 100%; padding: 13px 14px; font: 500 17px var(--body); color: var(--text);
  background: #0e1014; border: 1px solid var(--line-2); border-radius: 3px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: #555b66; }
.field input:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(245, 184, 46, .15); }
#roomInput { font-family: var(--mono); letter-spacing: .25em; text-transform: uppercase; }
.room-row { display: flex; gap: 8px; }
.ghost {
  flex: none; padding: 0 14px; font-size: 14px; color: var(--text);
  background: transparent; border: 1px solid var(--line-2); border-radius: 3px; transition: .15s;
}
.ghost:hover { border-color: var(--amber); color: var(--amber); }

.primary {
  position: relative; width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 15px 18px; margin-top: 6px; border: 0; border-radius: 3px;
  background: var(--amber); color: #15130d; font: 800 18px/1 var(--body); letter-spacing: .2em;
  box-shadow: 0 4px 0 var(--amber-deep), 0 12px 30px rgba(245, 184, 46, .22);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.primary i { font-style: normal; font-size: 22px; transition: transform .2s; }
.primary:hover { filter: brightness(1.06); }
.primary:hover i { transform: translateX(4px); }
.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--amber-deep), 0 6px 16px rgba(245, 184, 46, .2); }
.primary.small { font-size: 15px; letter-spacing: .1em; padding: 13px 16px; }
.err { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: #ff7b6e; }

.keys { display: flex; gap: 18px; margin-top: 14px; padding-top: 18px; border-top: 1px dashed var(--line-2); }
.keygroup { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.keygroup small { font-size: 12px; color: var(--muted); }
.kb { display: grid; grid-template-columns: repeat(3, 30px); gap: 4px; justify-content: center; }
.kb .k-up { grid-column: 2; }
.kb kbd:nth-child(2) { grid-column: 1; grid-row: 2; }
.kb kbd:nth-child(3) { grid-column: 2; grid-row: 2; }
.kb kbd:nth-child(4) { grid-column: 3; grid-row: 2; }
kbd {
  display: grid; place-items: center; height: 30px; font: 700 13px var(--display); color: #d9d4c6;
  background: linear-gradient(#2b3038, #22262d); border: 1px solid #3d434e; border-bottom-width: 3px; border-radius: 4px;
}
.kb kbd.space { grid-column: 1 / -1; grid-row: 2; width: 110px; letter-spacing: .2em; justify-self: center; }
.keygroup:last-child .kb { grid-template-columns: 110px; grid-template-rows: 30px 30px; }

/* ======================= 游戏 ======================= */
#game { position: relative; z-index: 2; display: flex; flex-direction: column; height: 100%; }

#topbar {
  flex: none; height: 56px; display: flex; align-items: center; gap: 22px; padding: 0 22px;
  border-bottom: 1px solid var(--line); background: rgba(14, 16, 20, .7); backdrop-filter: blur(8px);
}
.brand { font: 700 24px/1 var(--display); letter-spacing: .04em; color: var(--text); }
.brand b { color: var(--amber); margin-left: 2px; }
.lbl { font: 600 11px/1 var(--display); letter-spacing: .25em; color: var(--muted); margin-right: 8px; }
.room-chip { display: flex; align-items: center; padding: 6px 6px 6px 12px; border: 1px solid var(--line-2); border-radius: 3px; background: var(--ink-2); }
.room-chip b { font: 600 16px var(--mono); letter-spacing: .2em; color: var(--amber); margin-right: 12px; }
.room-chip button {
  font-size: 12px; color: var(--text); background: var(--ink-3); border: 1px solid var(--line-2);
  border-radius: 2px; padding: 5px 10px; transition: .15s;
}
.room-chip button:hover { border-color: var(--amber); color: var(--amber); }
.round { margin-left: auto; display: flex; align-items: baseline; }
.round b { font: 700 28px/1 var(--display); color: var(--text); min-width: 2ch; }
.ping { display: flex; align-items: center; gap: 8px; font: 13px var(--mono); color: var(--muted); min-width: 82px; }
.ping i { width: 8px; height: 8px; border-radius: 50%; background: #555; }

#arena { position: relative; flex: 1; min-height: 0; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* 等待面板 */
#waiting { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 12, 15, .55); backdrop-filter: blur(3px); }
.w-card {
  width: min(560px, 92%); text-align: left; padding: 26px 28px 24px; border-radius: 4px; position: relative;
  background: linear-gradient(180deg, #20242b, #171a1f); border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6); animation: rise .5s ease both;
}
.w-card::before {
  content: ""; position: absolute; left: -1px; right: -1px; top: -1px; height: 5px; border-radius: 4px 4px 0 0;
  background: repeating-linear-gradient(-45deg, var(--amber) 0 10px, #111 10px 20px);
}
.w-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.w-title { font: 900 28px var(--body); letter-spacing: .18em; }
.w-sub { font-size: 13px; color: var(--muted); margin-top: 6px; }
.w-code { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.w-code span { font-size: 11px; color: var(--muted); letter-spacing: .3em; }
.w-code b { font: 700 40px/1 var(--mono); letter-spacing: .2em; color: var(--amber); text-shadow: 0 0 30px rgba(245, 184, 46, .3); }

.w-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 22px; }
.w-slot {
  position: relative; height: 96px; border: 1px dashed var(--line-2); border-radius: 3px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; font-size: 12px; color: #5d636e; transition: border-color .2s, background .2s;
}
.w-slot.filled { border-style: solid; color: var(--text); background: linear-gradient(180deg, color-mix(in srgb, var(--c) 14%, transparent), rgba(255,255,255,.02)); border-color: color-mix(in srgb, var(--c) 45%, var(--line-2)); }
.w-slot.me { box-shadow: 0 0 0 1px var(--c), 0 0 18px color-mix(in srgb, var(--c) 30%, transparent); }
.w-slot.pop { animation: pop .35s ease; }
.w-slot .nm { font-weight: 700; max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-slot .host-badge, .w-slot .me-badge {
  position: absolute; top: 5px; font: 700 10px/1 var(--display); letter-spacing: .12em; padding: 3px 5px 2px; border-radius: 2px;
}
.w-slot .host-badge { left: 5px; background: var(--amber); color: #111; }
.w-slot .me-badge { right: 5px; background: var(--c); color: #111; }
@keyframes pop { 50% { transform: scale(1.06); } }

.w-section { margin-bottom: 22px; }
.w-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.w-label span { font: 600 12px/1 var(--display); letter-spacing: .22em; color: var(--muted); }
.w-label i { font-style: normal; font-size: 12px; color: #5f6570; }
.w-colors { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; padding-bottom: 14px; }
.swatch {
  position: relative; aspect-ratio: 1; border-radius: 4px; border: 0; padding: 0;
  background: var(--c); box-shadow: inset 0 -4px 0 rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform .12s, box-shadow .12s;
}
.swatch:hover:not(:disabled) { transform: translateY(-2px); }
.swatch.mine { box-shadow: 0 0 0 2px #15171b, 0 0 0 4px var(--c), 0 0 16px var(--c); }
.swatch.mine::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #111; font-weight: 900; font-size: 16px; }
.swatch:disabled { cursor: not-allowed; opacity: .32; filter: saturate(.5); }
.swatch .owner {
  position: absolute; left: 50%; bottom: -3px; transform: translate(-50%, 100%); white-space: nowrap;
  font-size: 10px; color: var(--muted); max-width: 60px; overflow: hidden; text-overflow: ellipsis;
}
.swatch:disabled .owner { opacity: 1; }

.w-actions { display: flex; gap: 10px; align-items: stretch; padding-top: 18px; border-top: 1px dashed var(--line-2); }
.w-actions .ghost { padding: 0 16px; }
.w-actions .primary { flex: 1; margin-top: 0; width: auto; }
.w-actions .primary:disabled { background: #3a3f48; color: #8a8f99; box-shadow: none; cursor: not-allowed; filter: none; }
.w-actions .primary:disabled i { transform: none; }
.wait-host {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 15px; font-weight: 700;
  color: var(--muted); letter-spacing: .1em; border: 1px dashed var(--line-2); border-radius: 3px; padding: 12px;
}
.wait-host::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); animation: blink 1.2s infinite; }

.stop-btn {
  font-size: 12px; font-weight: 700; letter-spacing: .08em; color: #ff8a7e; background: transparent;
  border: 1px solid rgba(255, 107, 94, .4); border-radius: 3px; padding: 7px 12px; transition: .15s;
}
.stop-btn:hover { background: rgba(255, 107, 94, .12); border-color: #ff6b5e; }

/* 回合横幅 */
#banner {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  text-align: center; pointer-events: none; padding: 26px 0 28px;
  background: linear-gradient(90deg, transparent, rgba(10, 11, 14, .82) 20%, rgba(10, 11, 14, .82) 80%, transparent);
  animation: bannerIn .45s cubic-bezier(.2, 1.4, .4, 1) both;
}
#banner.out { animation: bannerOut .35s ease both; }
.b-sub { font: 600 14px/1 var(--display); letter-spacing: .5em; color: var(--muted); margin-bottom: 10px; }
.b-main { font: 900 clamp(34px, 5vw, 64px)/1.05 var(--body); letter-spacing: .08em; }
.b-main .en { font-family: var(--display); font-weight: 700; letter-spacing: .02em; }
@keyframes bannerIn { from { opacity: 0; transform: translateY(-50%) scaleY(.2); letter-spacing: .6em; } to { opacity: 1; transform: translateY(-50%) scaleY(1); } }
@keyframes bannerOut { to { opacity: 0; transform: translateY(-50%) scaleY(.2); } }

/* 战报 */
#feed { position: absolute; top: 14px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; }
.feed-item {
  font-size: 13px; padding: 7px 12px 7px 10px; border-radius: 2px; color: var(--text);
  background: rgba(12, 14, 18, .82); border-left: 3px solid var(--c, var(--amber));
  animation: feedIn .3s ease both;
}
.feed-item.out { animation: feedOut .5s ease both; }
@keyframes feedIn { from { opacity: 0; transform: translateX(20px); } }
@keyframes feedOut { to { opacity: 0; transform: translateX(20px); } }

#toast {
  position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 20px); opacity: 0;
  padding: 9px 16px; background: var(--amber); color: #15130d; font-weight: 700; font-size: 14px; border-radius: 3px;
  transition: .25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 玩家卡片 */
#players {
  flex: none; height: 96px; display: flex; justify-content: center; align-items: center; gap: 14px;
  padding: 0 20px; border-top: 1px solid var(--line); background: rgba(14, 16, 20, .75); backdrop-filter: blur(8px);
}
.pcard {
  position: relative; width: 230px; height: 70px; display: grid;
  grid-template-columns: 54px 1fr auto; align-items: center; gap: 10px; padding: 0 14px 0 12px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 16%, #1b1e24), #1b1e24 70%);
  border: 1px solid var(--line-2); border-radius: 3px; overflow: hidden; transition: opacity .3s, filter .3s;
}
.pcard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.pcard.me { border-color: color-mix(in srgb, var(--c) 70%, #fff 0%); box-shadow: 0 0 0 1px var(--c), 0 0 24px color-mix(in srgb, var(--c) 30%, transparent); }
.pcard.dead { filter: grayscale(.85); opacity: .55; }
.pcard.dead .pc-state { color: #ff7b6e; }
.pcard canvas { width: 54px; height: 40px; }
.pc-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
.pc-name .you { font: 700 10px/1 var(--display); letter-spacing: .15em; color: #111; background: var(--c); padding: 2px 4px 1px; border-radius: 2px; margin-left: 6px; vertical-align: 2px; }
.pc-meta { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.pc-ammo { display: flex; gap: 3px; }
.pc-ammo i { width: 5px; height: 11px; border-radius: 1px; background: var(--c); transition: .15s; }
.pc-ammo i.used { background: #3a3f48; }
.pc-state { font-size: 11px; color: var(--muted); letter-spacing: .1em; }
.pc-score { font: 700 44px/1 var(--display); color: var(--text); min-width: 1.2ch; text-align: right; }
.pc-score.bump { animation: bump .6s ease; }
@keyframes bump { 30% { transform: scale(1.5); color: var(--c); } }
.pcard .crown { position: absolute; top: 4px; right: 6px; font-size: 11px; color: var(--amber); }
.pcard.empty { --c: #333; justify-content: center; display: flex; color: #4f5560; font-size: 13px; border-style: dashed; background: transparent; }
.pcard.empty::before { display: none; }

@media (max-width: 860px) {
  #lobby { grid-template-columns: 1fr; overflow: auto; padding: 40px 22px; align-content: start; }
  .pcard { width: 170px; grid-template-columns: 40px 1fr auto; }
  .pcard canvas { width: 40px; height: 30px; }
  .room-chip button { display: none; }
}
