/* 荒野守卫军 · 双人 PK —— 界面样式
   配色沿用 8.2 的低饱和奇幻皮：羊皮纸、旧铜、暗木，加一对蓝／红阵营色。 */

:root {
  --ink: #17110c;
  --parch: #E8D9B5;
  --parch-d: #C9B487;
  --wood: #4A3524;
  --wood-d: #2E2117;
  --wood-l: #6B4E33;
  --gold: #E0B34A;
  --gold-d: #9A7526;
  --blue: #3E8BE8;
  --blue-l: #8FC6FF;
  --red: #E0503A;
  --red-l: #FF9C82;
  --green: #7FB93B;
  --bg0: #16110c;
  --bg1: #241a12;
  --dock-h: 152px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--parch);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
}

button, input { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 800; letter-spacing: .04em; }

/* ================= 载入 ================= */
#boot {
  position: fixed; inset: 0; z-index: 900;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(120% 80% at 50% 30%, #33241a 0%, var(--bg0) 70%);
  transition: opacity .45s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }
.boot-crest, .crest-lg {
  width: 84px; height: 84px;
  background: conic-gradient(from 220deg, var(--gold), var(--gold-d) 40%, var(--gold) 60%, #6b4e2a 100%);
  clip-path: polygon(50% 0, 100% 22%, 100% 68%, 50% 100%, 0 68%, 0 22%);
  box-shadow: 0 10px 30px rgba(0,0,0,.55), inset 0 -8px 20px rgba(0,0,0,.35);
  position: relative;
}
.boot-crest::after, .crest-lg::after {
  content: ''; position: absolute; inset: 22%;
  background: var(--wood-d);
  clip-path: polygon(50% 0, 100% 30%, 76% 100%, 24% 100%, 0 30%);
}
.crest-lg { width: 104px; height: 104px; }
.boot-title { font-size: 30px; font-weight: 900; letter-spacing: .3em; text-indent: .3em; color: var(--gold); }
.boot-sub { font-size: 13px; letter-spacing: .6em; text-indent: .6em; color: var(--parch-d); }
.boot-bar { width: min(60vw, 280px); height: 8px; border-radius: 5px; background: rgba(0,0,0,.5); overflow: hidden; border: 1px solid rgba(224,179,74,.3); }
.boot-bar i { display: block; height: 100%; width: 6%; background: linear-gradient(90deg, var(--gold-d), var(--gold)); transition: width .3s ease; }
.boot-tip { font-size: 12.5px; color: #9c8a6d; }

/* ================= 屏幕 ================= */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.on { display: flex; }

.topline {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-d) 100%);
  border-bottom: 2px solid rgba(0,0,0,.5);
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
.topline h2 { flex: 1; font-size: 17px; color: var(--parch); }
.stars-count { font-size: 14px; color: var(--gold); font-weight: 700; }

/* ================= 按钮 ================= */
.btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 12px 18px;
  border: 2px solid var(--wood-d);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--wood-l), var(--wood) 55%, var(--wood-d));
  color: var(--parch);
  font-weight: 700;
  box-shadow: 0 4px 0 rgba(0,0,0,.45), inset 0 1px 0 rgba(255,235,190,.16);
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.45); }
.btn small { font-size: 11.5px; font-weight: 500; opacity: .72; }
.btn-xl { padding: 15px 20px; font-size: 17px; width: 100%; }
.btn-primary { background: linear-gradient(180deg, #C98A3E, #A66B27 55%, #6E4415); border-color: #4a2d0e; }
.btn-ghost { background: rgba(20,15,10,.45); border-color: rgba(224,179,74,.28); box-shadow: none; font-weight: 600; }
.btn[disabled] { opacity: .42; pointer-events: none; }

.iconbtn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 2px solid var(--wood-d); border-radius: 10px;
  background: linear-gradient(180deg, var(--wood-l), var(--wood-d));
  color: var(--parch); font-size: 18px; font-weight: 800;
  cursor: pointer;
}
.iconbtn.sm { width: 32px; height: 32px; font-size: 15px; border-radius: 8px; }
.iconbtn:active { transform: translateY(2px); }
.linkbtn { background: none; border: 0; color: var(--gold); text-decoration: underline; cursor: pointer; }

/* ================= 主菜单 ================= */
#home { background: radial-gradient(130% 90% at 50% 15%, #3a2a1c 0%, var(--bg0) 72%); overflow-y: auto; }
.home-inner {
  margin: auto; padding: calc(24px + var(--safe-t)) 22px calc(24px + var(--safe-b));
  width: min(460px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
#home h1 { font-size: 30px; color: var(--gold); letter-spacing: .16em; text-shadow: 0 3px 0 rgba(0,0,0,.5); }
.tagline { margin: -6px 0 2px; font-size: 13px; color: #a2916f; letter-spacing: .1em; }

.name-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.name-row span { font-size: 13px; color: #a2916f; flex: 0 0 auto; }
.name-row input, .room-input {
  flex: 1; width: 100%;
  padding: 10px 12px;
  border: 2px solid rgba(224,179,74,.3); border-radius: 10px;
  background: rgba(12,9,6,.6); color: var(--parch);
  outline: none;
}
.name-row input:focus, .room-input:focus { border-color: var(--gold); }
.room-input { text-transform: uppercase; letter-spacing: .12em; text-align: center; font-weight: 700; }
#serverInput { text-transform: none; letter-spacing: 0; text-align: left; font-weight: 500; font-size: 13px; }

.home-btns { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.home-row2 { display: flex; gap: 10px; }
.home-row2 .btn { flex: 1; }

.home-stats { display: flex; gap: 8px; width: 100%; margin-top: 4px; }
.home-stats > div {
  flex: 1; text-align: center; padding: 8px 4px;
  background: rgba(12,9,6,.5); border: 1px solid rgba(224,179,74,.2); border-radius: 10px;
}
.home-stats b { display: block; font-size: 18px; color: var(--gold); }
.home-stats span { font-size: 11px; color: #93815f; }
.save-line { font-size: 11.5px; color: #6f6249; }

/* ================= 牌组 ================= */
#deck { background: var(--bg1); }
.deck-current {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
  padding: 10px 12px;
  background: rgba(0,0,0,.32);
  border-bottom: 2px solid rgba(0,0,0,.5);
}
.deck-hint { padding: 8px 14px; font-size: 12px; color: #9a886a; }
.deck-pool {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 9px;
  padding: 4px 12px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}

.card {
  position: relative; border-radius: 9px; overflow: hidden;
  border: 2px solid var(--wood-d);
  background: var(--wood-d);
  box-shadow: 0 3px 0 rgba(0,0,0,.4);
  cursor: pointer;
  aspect-ratio: 3 / 4;
}
.card canvas { display: block; width: 100%; height: auto; }
.card .cname {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 3px 4px 4px;
  font-size: 10.5px; font-weight: 700; text-align: center;
  background: linear-gradient(180deg, rgba(12,9,6,0), rgba(12,9,6,.92) 45%);
  text-shadow: 0 1px 2px #000;
  line-height: 1.15;
}
.card .ccost {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12.5px; font-weight: 900;
  color: #fff; background: #B569E0;
  border: 2px solid rgba(0,0,0,.5);
  box-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.card.picked { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(224,179,74,.45), 0 3px 0 rgba(0,0,0,.4); }
.card.picked::after { content: '✓'; position: absolute; top: 3px; right: 4px; color: var(--gold); font-weight: 900; text-shadow: 0 1px 3px #000; }
.card.empty { background: rgba(0,0,0,.4); border-style: dashed; border-color: rgba(224,179,74,.3); }

/* ================= 匹配中 ================= */
#lobby { background: radial-gradient(120% 80% at 50% 30%, #2b2135 0%, var(--bg0) 72%); }
.lobby-inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 24px; text-align: center; }
.lobby-inner h2 { font-size: 20px; color: var(--gold); }
.lobby-inner p { margin: 0; font-size: 13.5px; color: #a2916f; min-height: 20px; }
.lobby-room {
  font-size: 26px; font-weight: 900; letter-spacing: .22em;
  color: var(--parch); padding: 10px 20px;
  border: 2px dashed rgba(224,179,74,.5); border-radius: 12px;
  background: rgba(0,0,0,.35);
}
.spinner { display: flex; gap: 8px; }
.spinner i {
  width: 12px; height: 12px; border-radius: 50%; background: var(--gold);
  animation: bounce 1s infinite ease-in-out;
}
.spinner i:nth-child(2) { animation-delay: .16s; }
.spinner i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

/* ================= 战斗 ================= */
#battle { background: #0d0a07; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#cv { display: block; width: 100%; height: 100%; touch-action: none; }

#topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(6px + var(--safe-t)) 10px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(180deg, rgba(10,8,6,.82), rgba(10,8,6,0));
  pointer-events: none;
}
.side-tag { display: flex; align-items: center; gap: 6px; font-size: 12.5px; max-width: 38%; }
.side-tag b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 84px; }
.side-tag .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 8px currentColor; }
.side-tag.foe .dot { background: var(--red); color: var(--red); }
.side-tag.me .dot { background: var(--blue); color: var(--blue); }
.side-tag .crowns { font-size: 13px; font-weight: 800; color: var(--gold); white-space: nowrap; }
.clock {
  font-size: 19px; font-weight: 900; letter-spacing: .06em;
  padding: 3px 12px; border-radius: 999px;
  background: rgba(12,9,6,.72); border: 1px solid rgba(224,179,74,.34);
  color: var(--parch);
}
.clock.hot { color: #FFD24A; border-color: #FFD24A; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.net-tag {
  position: absolute; right: 8px; top: calc(46px + var(--safe-t));
  font-size: 10.5px; color: #93a08c; background: rgba(10,8,6,.6);
  padding: 2px 7px; border-radius: 6px; pointer-events: none;
}

.toast {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%);
  padding: 9px 16px; border-radius: 10px;
  background: rgba(12,9,6,.9); border: 1px solid rgba(224,179,74,.4);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  pointer-events: none; z-index: 5;
}
.big-msg {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 34px; font-weight: 900; letter-spacing: .18em;
  color: var(--gold); text-shadow: 0 4px 0 rgba(0,0,0,.6);
  pointer-events: none; z-index: 6;
  animation: bigin .5s ease both;
}
@keyframes bigin { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- 底部操作区 ---- */
#dock {
  flex: 0 0 auto;
  height: calc(var(--dock-h) + var(--safe-b));
  padding: 8px 8px calc(8px + var(--safe-b));
  display: flex; align-items: stretch; gap: 8px;
  background: linear-gradient(180deg, var(--wood) 0%, var(--wood-d) 100%);
  border-top: 3px solid rgba(0,0,0,.55);
  box-shadow: 0 -6px 18px rgba(0,0,0,.5);
}
.dock-left { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; width: 74px; }
.dock-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.dock-right { flex: 0 0 auto; width: 62px; display: flex; align-items: center; }

.btn-quiz {
  flex: 1; padding: 6px 4px; gap: 0;
  background: linear-gradient(180deg, #4a6ea8, #2f4a76 55%, #1d3050);
  border-color: #16233a;
}
.btn-quiz .q-mark {
  font-size: 20px; font-weight: 900; color: #BFE9FF; line-height: 1;
}
.btn-quiz span:nth-child(2) { font-size: 13px; letter-spacing: .08em; }
.btn-quiz small { font-size: 10px; }
.btn-quiz .q-cd { position: absolute; inset: 0; border-radius: 10px; overflow: hidden; pointer-events: none; }
.btn-quiz .q-cd i { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(6,10,18,.72); height: 0%; }
.dock-left .iconbtn { height: 30px; width: 100%; font-size: 13px; }

.elixir { display: flex; align-items: center; gap: 7px; }
.elixir-bar {
  position: relative; flex: 1; height: 16px; border-radius: 8px;
  background: rgba(8,6,4,.7); border: 2px solid rgba(0,0,0,.5);
  overflow: hidden;
}
.elixir-bar i {
  position: absolute; inset: 0; width: 50%;
  background: linear-gradient(180deg, #D98BF0, #A93FD0 60%, #7A1EA0);
  transition: width .1s linear;
}
.elixir-bar span {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1.5px), rgba(0,0,0,.55) calc(10% - 1.5px) 10%);
}
.elixir b { font-size: 16px; font-weight: 900; color: #E6A8F5; width: 24px; text-align: center; }
.elixir.full b { color: #FFD24A; }

.hand { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; min-height: 0; }
.hand .card { aspect-ratio: auto; height: 100%; }
.hand .card.dim { filter: grayscale(.65) brightness(.55); }
.hand .card.sel { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(224,179,74,.6), 0 0 18px rgba(224,179,74,.4); transform: translateY(-6px); }
.hand .card .cname { font-size: 9.5px; padding: 2px 2px 3px; }
.hand .card .ccost { width: 19px; height: 19px; font-size: 11px; }

.next-card { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; }
.next-card > span { font-size: 9.5px; color: #a2916f; }
.next-card .card { width: 100%; }
.next-card .card .cname { display: none; }

/* ================= 弹层 ================= */
.modal {
  position: fixed; inset: 0; z-index: 400;
  display: none; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(6,4,3,.72);
  backdrop-filter: blur(3px);
}
.modal.on { display: flex; }
.sheet {
  width: min(520px, 100%); max-height: 86vh;
  display: flex; flex-direction: column;
  border: 3px solid var(--wood-d); border-radius: 16px;
  background: linear-gradient(180deg, #2f2318, #1d1610);
  box-shadow: 0 20px 50px rgba(0,0,0,.7);
  overflow: hidden;
  animation: sheetin .22s ease both;
}
@keyframes sheetin { from { transform: translateY(18px) scale(.97); opacity: 0; } }
.scroll-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--wood-l), var(--wood));
  border-bottom: 2px solid rgba(0,0,0,.45);
}
.q-cat { flex: 1; font-weight: 800; font-size: 14.5px; color: var(--gold); }
.q-type { font-size: 12px; color: #b9a67f; }

.q-stem { padding: 14px 16px 8px; font-size: 15px; line-height: 1.6; overflow-y: auto; }
.q-options { padding: 0 12px 8px; display: flex; flex-direction: column; gap: 7px; overflow-y: auto; }
.q-opt {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 9px 11px; border-radius: 9px;
  border: 2px solid rgba(224,179,74,.22);
  background: rgba(12,9,6,.5);
  cursor: pointer; font-size: 14px; line-height: 1.45;
}
.q-opt b { flex: 0 0 auto; color: var(--gold); font-weight: 800; }
.q-opt.on { border-color: var(--gold); background: rgba(224,179,74,.16); }
.q-opt.right { border-color: var(--green); background: rgba(127,185,59,.2); }
.q-opt.wrong { border-color: var(--red); background: rgba(224,80,58,.18); }
.q-foot { display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(12px + var(--safe-b)); border-top: 1px solid rgba(0,0,0,.4); }
.q-reward { flex: 1; font-size: 12.5px; color: #b9a67f; }
.q-result { padding: 10px 16px 14px; font-size: 13.5px; line-height: 1.55; color: #c8b48a; border-top: 1px solid rgba(0,0,0,.4); }

.small-sheet .set-body, .set-sheet .set-body { padding: 14px 16px calc(16px + var(--safe-b)); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.set-note { margin: 0; font-size: 12.5px; color: #9a886a; line-height: 1.6; }
.set-h { font-size: 13px; color: var(--gold); margin-top: 4px; }
.set-row { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.set-row span { flex: 0 0 46px; }
.set-row input[type=range] { flex: 1; accent-color: var(--gold); }
.set-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--gold); }
.set-row b { width: 34px; text-align: right; color: var(--gold); }
.set-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.set-grid > div { text-align: center; padding: 9px 4px; background: rgba(12,9,6,.5); border: 1px solid rgba(224,179,74,.18); border-radius: 9px; }
.set-grid b { display: block; font-size: 17px; color: var(--gold); }
.set-grid span { font-size: 11px; color: #93815f; }
.set-acts { display: flex; gap: 10px; }
.set-acts .btn { flex: 1; }
.lv-row { display: flex; flex-direction: column; gap: 9px; }
.lv-row .btn { width: 100%; }

/* ---- 结算 ---- */
.result-sheet { align-items: center; text-align: center; padding: 22px 18px calc(18px + var(--safe-b)); gap: 10px; }
.res-crowns { font-size: 34px; letter-spacing: .1em; }
.result-sheet h3 { font-size: 26px; color: var(--gold); letter-spacing: .2em; }
.res-reason { margin: 0; font-size: 13px; color: #9a886a; }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.res-grid > div { padding: 9px 4px; background: rgba(12,9,6,.5); border: 1px solid rgba(224,179,74,.18); border-radius: 9px; }
.res-grid b { display: block; font-size: 17px; color: var(--gold); }
.res-grid span { font-size: 11px; color: #93815f; }
.res-btns { display: flex; gap: 10px; width: 100%; margin-top: 4px; }
.res-btns .btn { flex: 1; }

/* ---- 横屏／大屏：把竞技场限宽居中 ---- */
@media (min-aspect-ratio: 1/1) {
  #stage { display: grid; place-items: center; }
  #cv { width: auto; height: 100%; max-width: 100%; aspect-ratio: 9 / 16; }
  #dock { max-width: 720px; margin: 0 auto; width: 100%; }
}
@media (max-height: 620px) {
  :root { --dock-h: 124px; }
  .btn-quiz .q-mark { font-size: 16px; }
}
