@font-face {
  font-family: "Righteous";
  src: url("../fonts/Righteous-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #e6e6e6;
  --card: #fbfbfb;
  --ink: #2a2a2a;
  --mute: #7a7a7a;
  --line: #d9d9d9;
  --red: #f53514;
  --red-dark: #77160d;
  --blue: #4bb4f8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}

input, button, select { font: inherit; color: inherit; }
input { -webkit-user-select: text; user-select: text; }

.hidden { display: none !important; }

.screen { display: none; position: fixed; inset: 0; overflow-y: auto; }
.screen.active { display: block; }

.panel {
  width: 100%; max-width: 440px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) 20px calc(env(safe-area-inset-bottom) + 28px);
  display: flex; flex-direction: column; gap: 14px;
  min-height: 100%;
}

/* ---------- 首页 ---------- */
#home .panel { justify-content: center; }
.logo {
  margin: 0; text-align: center;
  font-size: 54px; font-weight: 900; letter-spacing: 4px; line-height: 1.1;
  color: var(--red-dark);
  text-shadow: 0 3px 0 #fff;
}
.tagline { margin: 0 0 18px; text-align: center; color: var(--mute); letter-spacing: 6px; font-size: 14px; }

.field { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 4px 16px; }
.field span { color: var(--mute); font-size: 14px; white-space: nowrap; }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 44px; font-size: 17px; font-weight: 600; }

.btn {
  border: 0; border-radius: 14px; height: 52px; padding: 0 20px;
  background: var(--card); font-size: 17px; font-weight: 700; cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--red); color: #fff; box-shadow: 0 4px 0 var(--red-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--red-dark); transform: translateY(3px); }
.btn.ghost { background: transparent; border: 2px solid #c9c9c9; color: #555; }
.btn:disabled { filter: grayscale(1); opacity: .55; cursor: default; box-shadow: none; }

.joinrow { display: flex; gap: 10px; }
.joinrow input {
  flex: 1; min-width: 0; height: 52px; border: 0; outline: 0; border-radius: 14px; background: var(--card);
  text-align: center; font-family: "Righteous", sans-serif; font-size: 24px; letter-spacing: 8px;
}
.joinrow input::placeholder { font-family: inherit; font-size: 15px; letter-spacing: 0; color: #aaa; }

.homefoot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.net { font-size: 13px; color: var(--mute); }
.net.ok::before { content: "● "; color: #3cb85a; }
.net.bad::before { content: "● "; color: #d9a01e; }
.link { border: 0; background: none; color: #555; font-size: 14px; font-weight: 600; padding: 8px 4px; cursor: pointer; }

/* ---------- 房间 ---------- */
.roomhead { display: flex; align-items: center; justify-content: space-between; }
.roomcode { font-size: 14px; color: var(--mute); }
.roomcode b { font-family: "Righteous", sans-serif; font-size: 30px; letter-spacing: 3px; color: var(--ink); margin-left: 4px; vertical-align: -3px; }

.row { background: var(--card); border-radius: 14px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; min-height: 56px; }
.row.col { flex-direction: column; align-items: stretch; gap: 4px; }
.rowline { display: flex; align-items: center; gap: 12px; }
.rowlabel { color: var(--mute); font-size: 14px; white-space: nowrap; width: 34px; }
.rowline b { font-family: "Righteous", sans-serif; font-size: 20px; width: 30px; text-align: right; }
.rowline input[type=range] { flex: 1; min-width: 0; accent-color: var(--red); height: 32px; }

.seg { display: flex; flex: 1; background: #e9e9e9; border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; height: 36px; border-radius: 8px; font-weight: 700; color: #777; cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button:disabled { cursor: default; }

.seats { display: flex; flex-direction: column; gap: 8px; }
.seat { background: var(--card); border-radius: 14px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.seat .sw { width: 34px; height: 34px; border-radius: 50%; border: 4px solid; flex: none; cursor: pointer; padding: 0; }
.seat .sw:disabled { cursor: default; }
.seat .who { flex: 1; min-width: 0; }
.seat .who .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .who .tag { font-size: 12px; color: var(--mute); }
.seat.open .nm { color: #aaa; font-weight: 500; }
.seat select { border: 0; background: #ececec; border-radius: 10px; height: 36px; padding: 0 8px; font-size: 14px; font-weight: 600; max-width: 130px; }
.seat .kick { border: 0; background: #ececec; border-radius: 10px; height: 36px; padding: 0 12px; font-size: 14px; color: #666; cursor: pointer; }

.mapbtn { flex: 1; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 0; cursor: pointer; text-align: left; min-width: 0; }
.mapbtn canvas { width: 44px; height: 54px; border-radius: 8px; background: var(--bg); flex: none; }
.mapbtn span { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mapbtn i { font-style: normal; color: #aaa; font-size: 22px; }
.mapbtn:disabled { cursor: default; }
.mapbtn:disabled i { visibility: hidden; }

.hint { font-size: 12.5px; color: var(--mute); line-height: 1.5; margin: 0; }
.hint.center { text-align: center; min-height: 18px; }

/* ---------- 对局 ---------- */
#game { overflow: hidden; background: var(--bg); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-family: "Righteous", sans-serif; font-size: 140px; color: rgba(40,40,40,.82);
  text-shadow: 0 4px 0 rgba(255,255,255,.7);
}
.countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .15; } }

.banner {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px); transform: translateX(-50%);
  background: rgba(40,40,40,.82); color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 14px; white-space: nowrap; pointer-events: none;
}

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.38); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 20px; }
.card { background: #fff; border-radius: 20px; padding: 26px 22px 22px; width: 100%; max-width: 320px; text-align: center; display: flex; flex-direction: column; gap: 12px; animation: rise .22s ease-out; }
.card h2 { margin: 0; font-size: 40px; letter-spacing: 6px; color: var(--red-dark); }
.card h2.lose { color: #555; }
.card h3 { margin: 0; font-size: 20px; }
.card p { margin: 0; color: var(--mute); font-size: 14px; }
.btnrow { display: flex; gap: 10px; }
.btnrow .btn { flex: 1; padding: 0 8px; font-size: 16px; }
.btnrow .btn:first-child { background: #eee; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet { background: var(--bg); border-radius: 20px; width: 100%; max-width: 520px; max-height: 86vh; display: flex; flex-direction: column; padding: 16px 16px 8px; gap: 8px; animation: rise .22s ease-out; }
.sheethead { display: flex; align-items: center; justify-content: space-between; }
.sheethead h3 { margin: 0; font-size: 19px; }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; overflow-y: auto; padding: 4px 2px 12px; }
.mapcard { background: var(--card); border: 3px solid transparent; border-radius: 14px; padding: 6px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.mapcard.on { border-color: var(--red); }
.mapcard canvas { width: 84px; height: 100px; }
.mapcard .rnd { width: 84px; height: 100px; display: flex; align-items: center; justify-content: center; font-family: "Righteous", sans-serif; font-size: 52px; color: #bbb; }
.mapcard .mn { font-size: 13px; font-weight: 700; text-align: center; line-height: 1.2; }
.mapcard .mt { font-size: 11px; color: var(--mute); }
.mapcard .mt.exact { color: var(--red); font-weight: 700; }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 18px); transform: translateX(-50%); z-index: 40;
  background: rgba(40,40,40,.9); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 14px; max-width: 86vw; text-align: center;
}
.offline {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: #d9a01e; color: #fff; font-size: 13px; text-align: center;
}

@media (max-height: 640px) {
  .logo { font-size: 42px; }
  .panel { gap: 10px; padding-top: calc(env(safe-area-inset-top) + 14px); }
  .btn { height: 46px; }
}

/* ---------- 选位栏 ---------- */
.pickbar {
  position: absolute; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px);
  background: rgba(255,255,255,.96); border-radius: 18px; padding: 10px 12px 12px 14px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 4px 18px rgba(0,0,0,.14);
  max-width: 520px; margin: 0 auto;
}
.picktimer { font-family: "Righteous", sans-serif; font-size: 30px; width: 40px; text-align: center; color: var(--red-dark); flex: none; }
.picktext { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.picktext b { font-size: 16px; }
.picktext span { font-size: 12.5px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pickbar .btn { height: 46px; padding: 0 22px; flex: none; }
