* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #4fb0ee;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #2b1b0e;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  display: block;
}

.hidden {
  display: none !important;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
}

#hud button {
  pointer-events: auto;
}

.hud-left {
  font-size: 15px;
  line-height: 1.6;
  font-weight: 700;
}

.hud-center {
  text-align: center;
}

#hud-score {
  font-family: "Arial Black", "Microsoft YaHei", sans-serif;
  font-size: 36px;
  font-weight: 900;
  line-height: 1.1;
}

#hud-pigs {
  font-size: 15px;
  font-weight: 700;
  white-space: pre;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#hud-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid var(--c);
  font-size: 13px;
  text-shadow: none;
}

.chip.on {
  background: var(--c);
}

#hint {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- panels ---------- */

.panel-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 40, 70, 0.35);
  backdrop-filter: blur(3px);
}

.panel {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 28px;
  border-radius: 20px;
  background: linear-gradient(#fff8e8, #ffe7bf);
  border: 4px solid #7a4a1f;
  box-shadow: 0 10px 0 #5e3518, 0 18px 40px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.panel h1 {
  font-family: "Arial Black", "Microsoft YaHei", sans-serif;
  font-size: 40px;
  color: #d62828;
  text-shadow: 0 3px 0 #7a1010;
  letter-spacing: 2px;
}

.panel h2 {
  font-size: 26px;
  color: #7a4a1f;
  margin-bottom: 12px;
}

.sub {
  margin: 6px 0 18px;
  color: #7a5a3a;
  font-size: 14px;
}

.big {
  font-size: 20px;
  margin: 6px 0 10px;
}

#ov-body p {
  margin: 6px 0;
}

.field {
  margin-bottom: 14px;
  text-align: left;
}

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #5e3518;
}

.seg {
  display: flex;
  gap: 8px;
}

.seg-btn {
  flex: 1;
  padding: 8px 0;
  border-radius: 10px;
  border: 2px solid #b8763a;
  background: #fff;
  color: #7a4a1f;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.seg-btn.active {
  background: #f4a261;
  color: #fff;
  border-color: #c66a1f;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
}

.name-row input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 2px solid #d9b98f;
  font-size: 15px;
  background: #fff;
  user-select: text;
}

.name-row input:focus {
  outline: none;
  border-color: #f4a261;
}

.btn {
  padding: 10px 22px;
  border-radius: 12px;
  border: none;
  background: #e9d5b5;
  color: #5e3518;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b99d74;
  transition: transform 0.08s;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b99d74;
}

.btn.primary {
  background: linear-gradient(#ff6b6b, #d62828);
  color: #fff;
  box-shadow: 0 4px 0 #8a1414;
}

.btn.small {
  padding: 5px 14px;
  font-size: 13px;
}

.btn.wide {
  width: 100%;
  font-size: 20px;
  padding: 12px;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 18px;
  text-align: left;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
}

.legend-item canvas {
  width: 32px;
  height: 32px;
  flex: none;
}

.legend-item b {
  display: block;
  font-size: 13px;
}

.legend-item small {
  font-size: 11px;
  color: #7a5a3a;
}

.best {
  margin-top: 16px;
  text-align: left;
}

.best h3 {
  font-size: 15px;
  color: #5e3518;
  margin-bottom: 6px;
}

.best ol {
  padding-left: 22px;
  font-size: 13px;
}

.best li span {
  display: inline-block;
  min-width: 90px;
}

.best li small {
  margin-left: 8px;
  color: #9a7a5a;
}

.board {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 15px;
}

.board th,
.board td {
  padding: 7px 6px;
  border-bottom: 1px solid #e3c79c;
}

.board th {
  color: #7a4a1f;
}

@media (max-width: 640px) {
  .panel h1 {
    font-size: 30px;
  }

  #hud-score {
    font-size: 26px;
  }

  .hud-left,
  #hud-pigs {
    font-size: 12px;
  }

  #hint {
    font-size: 11px;
  }
}
